### Download Example Data Source: https://context7.com/sj001/ai-feynman/llms.txt Downloads example datasets from the MIT Feynman Symbolic Regression Database. Useful for testing and experimentation with the library. ```python import aifeynman # Download example data files from MIT server aifeynman.get_demos("example_data") # Downloads files to ./example_data/ directory: # - example1.txt (I.8.14: kinetic energy) # - example2.txt (I.10.7: gravitational potential) # - example3.txt (I.50.26: etc.) # Run regression on downloaded example aifeynman.run_aifeynman( pathdir="./example_data/", filename="example1.txt", BF_try_time=60, BF_ops_file_type="14ops.txt", polyfit_deg=3, NN_epochs=500 ) ``` -------------------------------- ### Install AI Feynman Environment Source: https://github.com/sj001/ai-feynman/blob/master/README.md Commands to create a virtual environment and install the necessary Python packages. ```bash virtualenv -p python3 feyn source feyn/bin/activate pip install numpy pip install aifeynman ``` -------------------------------- ### Complete Symbolic Regression Workflow Source: https://context7.com/sj001/ai-feynman/llms.txt Demonstrates the full pipeline including directory setup, synthetic data generation, model execution, and result parsing. ```python import numpy as np import os import aifeynman # 1. Create working directories os.makedirs("./my_experiment/data/", exist_ok=True) # 2. Generate synthetic data for unknown equation # True equation: f(a,b,c) = sqrt(a^2 + b^2) * exp(-c) np.random.seed(42) n_points = 5000 a = np.random.uniform(0.1, 5.0, n_points) b = np.random.uniform(0.1, 5.0, n_points) c = np.random.uniform(0.0, 2.0, n_points) f = np.sqrt(a**2 + b**2) * np.exp(-c) # Add small noise (optional, tests robustness) noise = np.random.normal(0, 0.01 * np.std(f), n_points) f_noisy = f + noise # 3. Save data file data = np.column_stack([a, b, c, f_noisy]) np.savetxt("./my_experiment/data/mystery.txt", data, fmt="%.10f") # 4. Run AI Feynman aifeynman.run_aifeynman( pathdir="./my_experiment/data/", filename="mystery.txt", BF_try_time=120, # 2 minutes per brute force call BF_ops_file_type="14ops.txt", polyfit_deg=4, NN_epochs=2000, test_percentage=20 ) # 5. Load and display results print("\n=== Discovered Equations (Pareto Frontier) ===\n") try: results = np.loadtxt("results/solution_mystery.txt", dtype=str) if results.ndim == 1: results = results.reshape(1, -1) for i, row in enumerate(results): print(f"Solution {i+1}:") print(f" Expression: {row[-1]}") print(f" Test Error: {row[0]}") print(f" Complexity: {row[3]} bits\n") except Exception as e: print(f"Error loading results: {e}") ``` -------------------------------- ### Execute AI Feynman via Terminal Source: https://github.com/sj001/ai-feynman/blob/master/README.md Example of invoking the symbolic regression solver directly from the command line. ```bash python ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt ``` -------------------------------- ### Run AI Feynman Symbolic Regression Source: https://github.com/sj001/ai-feynman/blob/master/README.md Python script to download example data and execute the symbolic regression solver. ```python import aifeynman aifeynman.get_demos("example_data") # Download examples from server aifeynman.run_aifeynman("./example_data/", "example1.txt", 60, "14ops.txt", polyfit_deg=3, NN_epochs=500) ``` -------------------------------- ### Run AI Feynman Symbolic Regression Source: https://context7.com/sj001/ai-feynman/llms.txt Primary entry point for symbolic regression. Requires data file and configuration for search parameters. Results are saved to results/solution_.txt. ```python import aifeynman import numpy as np # Create sample data for the equation: f(x,y) = x^2 + y # Data format: columns are [x, y, f(x,y)] separated by spaces data = np.column_stack([ np.random.uniform(0.1, 5.0, 1000), # x values np.random.uniform(0.1, 5.0, 1000), # y values ]) data = np.column_stack([data, data[:,0]**2 + data[:,1]]) # add f(x,y) column np.savetxt("./my_data/", data) # Run AI Feynman symbolic regression aifeynman.run_aifeynman( pathdir="./my_data/", # Directory containing the data file filename="mystery.txt", # Name of the data file BF_try_time=60, # Brute force search time limit (seconds) BF_ops_file_type="14ops.txt", # Operations file (7ops, 10ops, 14ops, or 19ops) polyfit_deg=4, # Maximum polynomial degree to try NN_epochs=4000, # Neural network training epochs vars_name=[], # Optional: variable names for dimensional analysis test_percentage=20 # Percentage of data for test set ) # Results saved to results/solution_mystery.txt # Each row: [test_error] log_err log_err_cumulative complexity error symbolic_expression # Example output row: -15.2 -12000.5 25 1.2e-5 x0**2 + x1 ``` -------------------------------- ### Prepare Input Data Source: https://context7.com/sj001/ai-feynman/llms.txt Generates a space-separated text file containing independent variables followed by the dependent variable. ```python import numpy as np # Example: Create data for f(x1, x2, x3) = sin(x1) + x2*x3 n_samples = 10000 x1 = np.random.uniform(-np.pi, np.pi, n_samples) x2 = np.random.uniform(0.1, 10, n_samples) x3 = np.random.uniform(0.1, 10, n_samples) y = np.sin(x1) + x2 * x3 # Stack columns: [x1, x2, x3, y] data = np.column_stack([x1, x2, x3, y]) # Save with spaces (also supports tabs and commas) np.savetxt("./data/my_function.txt", data, fmt="%.8f") ``` -------------------------------- ### Run AI Feynman Regression Source: https://context7.com/sj001/ai-feynman/llms.txt Executes the symbolic regression process on a specified data file. Ensure the input file follows the required column-based format. ```python aifeynman.run_aifeynman( pathdir="./physics_data/", filename="gravity.txt", BF_try_time=120, BF_ops_file_type="14ops.txt", polyfit_deg=4, NN_epochs=4000, vars_name=["G", "m1", "m2", "r", "F"], # Must match units.xlsx test_percentage=20 ) ``` ```python import aifeynman aifeynman.run_aifeynman( pathdir="./data/", filename="my_function.txt", BF_try_time=60, BF_ops_file_type="14ops.txt", polyfit_deg=3, NN_epochs=2000 ) ``` -------------------------------- ### Configure Operations Files for Brute-Force Search Source: https://context7.com/sj001/ai-feynman/llms.txt Selects the set of mathematical operations for the brute-force search. Different files offer trade-offs between search speed and complexity. ```python import aifeynman # 7ops.txt: Basic operations (fastest) # Symbols: + * D > ~ R 0 # Operations: add, multiply, divide, greater-than, negate, sqrt, zero aifeynman.run_aifeynman("./data/", "file.txt", 30, "7ops.txt") # 14ops.txt: Standard operations (recommended) # Symbols: + * - D > < ~ I R P S C L E # Operations: add, multiply, subtract, divide, >, <, negate, # inverse, sqrt, power, sin, cos, log, exp aifeynman.run_aifeynman("./data/", "file.txt", 60, "14ops.txt") # 10ops.txt and 19ops.txt also available for intermediate/extended searches ``` -------------------------------- ### Enable Dimensional Analysis with Variable Names Source: https://context7.com/sj001/ai-feynman/llms.txt Provides variable names and units to AI Feynman for dimensional analysis, reducing problem complexity by identifying dimensionless combinations. Requires data and a units.xlsx file. ```python import aifeynman import numpy as np # Data for gravitational force: F = G*m1*m2/r^2 # Variables: G (gravitational constant), m1, m2 (masses), r (distance), F (force) G_vals = np.full(1000, 6.674e-11) m1_vals = np.random.uniform(1e20, 1e25, 1000) m2_vals = np.random.uniform(1e20, 1e25, 1000) r_vals = np.random.uniform(1e6, 1e9, 1000) F_vals = G_vals * m1_vals * m2_vals / r_vals**2 data = np.column_stack([G_vals, m1_vals, m2_vals, r_vals, F_vals]) np.savetxt("./physics_data/gravity.txt", data) # Provide variable names matching entries in units.xlsx ``` -------------------------------- ### Parse Regression Results Source: https://context7.com/sj001/ai-feynman/llms.txt Reads the generated solution file to extract and display Pareto-optimal equations and their associated metrics. ```python import numpy as np import aifeynman # Run regression aifeynman.run_aifeynman("./data/", "example.txt", 60, "14ops.txt", test_percentage=20) # Read and parse results results = np.loadtxt("results/solution_example.txt", dtype=str) # With test_percentage > 0, columns are: # [test_error, log_error, cumulative_log_error, complexity, error, expression] for row in results: test_err = float(row[0]) # Error on held-out test set log_err = float(row[1]) # Mean log2 error (bits) cum_log_err = float(row[2]) # Cumulative log2 error complexity = float(row[3]) # Expression complexity (bits) error = float(row[4]) # Training error expression = row[5] # Symbolic expression (e.g., "x0**2 + sin(x1)") print(f"Expression: {expression}") print(f" Complexity: {complexity:.1f} bits") print(f" Training error: {error:.2e}") print(f" Test error: {test_err:.2e}") print() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.