AI-Feynman Documentation

repository·master·Indexed 21 days ago

https://github.com/sj001/ai-feynman

An implementation of the AI Feynman method for symbolic regression. It discovers physics-inspired mathematical equations from data using brute-force search, polynomial fitting, and neural networks. Supports Linux and Mac environments and provides both a Python API via aifeynman.run_aifeynman and a command-line interface.

Tokens
751
Snippets
3
Records
3
Agent score
23%

What's inside AI-Feynman

  1. Install AI-Feynman

    master

    AI-Feynman is supported only on Linux and Mac environments. It is recommended to use a fresh virtual environment.

    1. Create and activate a virtual environment:
      virtualenv -p python3 feyn
      source feyn/bin/activate
    2. Install dependencies:
      pip install numpy
    3. Install the package:
      pip install aifeynman
    4. Important: Before running the code, you must compile the Fortran files used for the brute force module by running:
      ./compile.sh
    virtualenv -p python3 feyn
    source feyn/bin/activate
    pip install numpy
    pip install aifeynman
    ./compile.sh
  2. Run AI-Feynman via Python API

    master

    You can use the aifeynman.run_aifeynman function to perform symbolic regression on a data file.

    Parameters:

    • pathdir: Path to the directory containing the data file.
    • filename: The name of the data file.
    • BF_try_time: Time limit for each brute force call (default: 60).
    • BF_ops_file_type: File containing the symbols for brute force (default: "14ops.txt").
    • polyfit_deg: Maximum degree of the polynomial tried (default: 4).
    • NN_epochs: Number of epochs for neural network training (default: 4000).
    • vars_name: A list of strings representing the names of the variables in the data file (including the output variable), in the same order as they appear in the file.
    • test_percentage: Percentage of input data to set aside for testing (default: 0).

    Data Format: The input file must be a text file where each column contains numerical values for each variable (dependent and independent). Columns can be separated by spaces, commas, or tabs.

    Output: Results are saved in a directory named results as solution_{filename}. Each row in the solution file represents a point on the Pareto frontier and contains:

    • Mean logarithm (base 2) of the error (average error in bits).
    • Cumulative logarithm (base 2) of the error.
    • Complexity of the equation (in bits).
    • Error of the equation on input data.
    • The symbolic expression of the equation.

    Note: If test_percentage > 0, the error on the test set is added as the first value in each row.

    import aifeynman
    
    # Download example data
    aifeynman.get_demos("example_data")
    
    # Run symbolic regression
    aifeynman.run_aifeynman(
        "./example_data/", 
        "example1.txt", 
        60, 
        "14ops.txt", 
        polyfit_deg=3, 
        NN_epochs=500
    )
  3. Run AI-Feynman via Command Line

    master

    You can call AI-Feynman from the terminal using the ai_feynman_terminal_example.py script. Use the --help flag to see all available parameters.

    Example usage:

    python ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
    python ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt