This project demonstrates an evolutionary approach to generating mathematical equations using an OpenAI-compatible LLM. The system attempts to approximate a hidden goal equation by iteratively generating and testing equations. aka inductive inference
- Hidden Goal: The system works against a hidden goal equation:
Y = X^2 + 2*X + 1 - LLM Generation: An OpenAI-compatible LLM generates new equations
- Evaluation: Each equation is tested against a set of input values
- Cost Calculation: The system calculates how well each equation matches the hidden goal
- Evolution: The process repeats, trying to minimize the cost over multiple iterations
- Uses an OpenAI-compatible API (defaulting to Ollama)
- Iterative equation generation and refinement
- Cost-based optimization against a hidden target
- Safe equation parsing and evaluation
- Progress tracking and reporting
- Python 3.7+
- OpenAI Python library
- Ollama or other OpenAI-compatible LLM service
- Install dependencies:
pip install openai numpy- Start an LLM service (e.g., Ollama):
ollama run llama3- Run the system:
python evolving_modeling.pyThe system will:
- Generate a set of input values
- Iteratively ask the LLM to generate equations
- Evaluate each equation against the hidden goal
- Track the best equation found so far
- Display progress and final results
You can modify:
- The hidden goal equation in
_define_hidden_goal() - Input ranges in
_generate_inputs() - Number of rounds in
evolve() - LLM parameters in
generate_equation()
Starting evolutionary modeling process...
Hidden goal: Y = X^2 + 2*X + 1
Input values: [-5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0]
--------------------------------------------------
Round 1
Generated equation: X**2 + 2*X + 1
Cost: 0.000000
New best equation: X**2 + 2*X + 1
Best cost so far: 0.000000
...
Evolution completed!
Best equation found: X**2 + 2*X + 1
Best cost achieved: 0.000000