Skip to content

porterchild/evolving_modeling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Evolutionary Modeling System

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

How It Works

  1. Hidden Goal: The system works against a hidden goal equation: Y = X^2 + 2*X + 1
  2. LLM Generation: An OpenAI-compatible LLM generates new equations
  3. Evaluation: Each equation is tested against a set of input values
  4. Cost Calculation: The system calculates how well each equation matches the hidden goal
  5. Evolution: The process repeats, trying to minimize the cost over multiple iterations

Features

  • 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

Requirements

  • Python 3.7+
  • OpenAI Python library
  • Ollama or other OpenAI-compatible LLM service

Setup

  1. Install dependencies:
pip install openai numpy
  1. Start an LLM service (e.g., Ollama):
ollama run llama3
  1. Run the system:
python evolving_modeling.py

Usage

The system will:

  1. Generate a set of input values
  2. Iteratively ask the LLM to generate equations
  3. Evaluate each equation against the hidden goal
  4. Track the best equation found so far
  5. Display progress and final results

Customization

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()

Example Output

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages