Skip to content

Commit a72ac78

Browse files
committed
fix memory for prompt at sampler
1 parent ba332b7 commit a72ac78

13 files changed

Lines changed: 1161 additions & 643 deletions
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Configuration for MAP-Elites with Adaptive Exploration + Memory
2+
# Combines adaptive search with memory-augmented evolution
3+
4+
# Evolution settings
5+
max_iterations: 100
6+
checkpoint_interval: 10
7+
log_level: "INFO"
8+
9+
# Memory Configuration - ENABLED
10+
memory:
11+
enabled: true
12+
load_from_snapshot: false # Start fresh
13+
semantic_search_topk: 3 # Number of similar parents from memory
14+
embed_model: "text-embedding-3-large" # OpenAI embedding model
15+
16+
# LLM configuration - SAME AS BASE CONFIG
17+
llm:
18+
primary_model: "gpt-5-mini"
19+
primary_model_weight: 0.8
20+
secondary_model: "gpt-5-nano"
21+
secondary_model_weight: 0.2
22+
api_base: "https://api.openai.com/v1"
23+
temperature: 0.6
24+
top_p: 0.95
25+
max_tokens: 32000
26+
timeout: 180
27+
28+
# Prompt configuration - SAME AS BASE CONFIG
29+
prompt:
30+
system_message: "You are an expert signal processing engineer specializing in real-time adaptive filtering algorithms. Your task is to improve a signal processing algorithm that filters volatile, non-stationary time series data using a sliding window approach. The algorithm must minimize noise while preserving signal dynamics with minimal computational latency and phase delay. Focus on the multi-objective optimization of: (1) Slope change minimization - reducing spurious directional reversals, (2) Lag error minimization - maintaining responsiveness, (3) Tracking accuracy - preserving genuine signal trends, and (4) False reversal penalty - avoiding noise-induced trend changes. Consider advanced techniques like adaptive filtering (Kalman filters, particle filters), multi-scale processing (wavelets, EMD), predictive enhancement (polynomial fitting, neural networks), and trend detection methods."
31+
num_top_programs: 3
32+
use_template_stochasticity: true
33+
# Memory rendering (from semantic search)
34+
num_similar_parent_best: 3
35+
num_similar_parent_worst: 3
36+
include_similar_parent_worst: true
37+
38+
# Database configuration - ADAPTIVE VERSION
39+
database:
40+
population_size: 80
41+
archive_size: 30
42+
num_islands: 4
43+
elite_selection_ratio: 0.15
44+
45+
# ADAPTIVE EXPLORATION/EXPLOITATION (NEW!)
46+
use_adaptive_search: true
47+
adaptive_window_size: 10 # Track last 10 iterations
48+
adaptive_min_exploration: 0.1 # When improving (10% explore, 80% exploit, 10% random)
49+
adaptive_max_exploration: 0.7 # When stuck (70% explore, 20% exploit, 10% random)
50+
51+
# Static fallback (if use_adaptive_search: false)
52+
exploration_ratio: 0.2
53+
exploitation_ratio: 0.65
54+
55+
# Evaluator configuration - SAME AS BASE CONFIG
56+
evaluator:
57+
timeout: 120
58+
cascade_evaluation: true
59+
cascade_thresholds: [0.3, 0.6]
60+
parallel_evaluations: 4
61+
use_llm_feedback: false
62+
63+
# Evolution settings - SAME AS BASE CONFIG
64+
diff_based_evolution: true
65+
max_code_length: 60000
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
# Run OpenEvolve with Adaptive Exploration/Exploitation + Memory for Signal Processing
3+
# This combines MAP-Elites with dynamic exploration/exploitation AND memory-augmented evolution
4+
5+
set -e # Exit on error
6+
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9+
10+
echo "=========================================="
11+
echo "OpenEvolve - Signal Processing"
12+
echo "Adaptive + Memory"
13+
echo "=========================================="
14+
echo "Strategy: MAP-Elites with Adaptive Search + Memory"
15+
echo "Adaptive: 10-70% exploration based on improvements"
16+
echo "Memory: Semantic search (text-embedding-3-large)"
17+
echo "Iterations: 100"
18+
echo "Models: gpt-5-mini (80%) + gpt-5-nano (20%)"
19+
echo "=========================================="
20+
21+
cd "$PROJECT_ROOT"
22+
23+
python openevolve-run.py \
24+
examples/signal_processing/initial_program.py \
25+
examples/signal_processing/evaluator.py \
26+
--config examples/signal_processing/config_adaptive_memory.yaml \
27+
--output openevolve_output_adaptive_memory \
28+
--iterations 100
29+
30+
echo ""
31+
echo "=========================================="
32+
echo "Adaptive + Memory run complete!"
33+
echo "Results saved in: openevolve_output_adaptive_memory/"
34+
echo "=========================================="

examples/symbolic_regression/analyze_results.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def find_best_program_info(
4747
# Special case: 'openevolve' is the default MAP-Elites strategy
4848
# Path: openevolve_output/best/best_program_info.json (no strategy subfolder)
4949
if strategy == "openevolve":
50-
info_file = problem_dir / "openevolve_output" / "best" / "best_program_info.json"
50+
info_file = problem_dir / "openevolve_output_adaptive_memory" / "best" / "best_program_info.json"
5151
else:
5252
# Other strategies: openevolve_output/{strategy}/best/best_program_info.json
53-
info_file = problem_dir / "openevolve_output" / strategy / "best" / "best_program_info.json"
53+
info_file = problem_dir / "openevolve_output_adaptive_memory" / strategy / "best" / "best_program_info.json"
5454

5555
if info_file.exists():
5656
return info_file
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Configuration for MAP-Elites with Adaptive Exploration + Memory - Symbolic Regression
2+
# Combines adaptive search with memory-augmented evolution
3+
4+
# Evolution settings
5+
max_iterations: 200
6+
checkpoint_interval: 10
7+
log_level: "INFO"
8+
random_seed: 42
9+
target_score: "combined_score"
10+
11+
# Memory Configuration - ENABLED
12+
memory:
13+
enabled: true
14+
load_from_snapshot: false # Start fresh
15+
semantic_search_topk: 3 # Number of similar parents from memory
16+
embed_model: "text-embedding-3-large" # OpenAI embedding model
17+
18+
# LLM configuration - SAME AS BASE CONFIG
19+
llm:
20+
primary_model: "gpt-4o"
21+
primary_model_weight: 0.8
22+
secondary_model: "o3"
23+
secondary_model_weight: 0.2
24+
api_base: "https://api.openai.com/v1"
25+
temperature: 0.7
26+
top_p: 0.95
27+
max_tokens: 8192
28+
timeout: 300
29+
30+
# Prompt configuration - SAME AS BASE CONFIG
31+
prompt:
32+
system_message: |
33+
You are an expert in symbolic regression and mathematical modeling.
34+
Your task is to evolve a Python function `func(x, params)` that models a scientific process,
35+
predicting output variables based on input variables.
36+
37+
The function signature is:
38+
```python
39+
def func(x: np.ndarray, params: np.ndarray) -> np.ndarray:
40+
```
41+
42+
- `x` is a 2D NumPy array of shape `(n_samples, n_features)` containing input variables
43+
- `params` is a 1D NumPy array of up to 10 parameters (optimized externally via BFGS)
44+
- The function should return a 1D NumPy array of predictions with shape `(n_samples,)`
45+
46+
Key principles:
47+
- Aim for accurate predictions with low mean squared error (MSE)
48+
- Prefer simple, interpretable mathematical expressions
49+
- Consider the physical meaning and relationships of input variables
50+
- Avoid numerical issues (division by zero, log of negative numbers, etc.)
51+
- Balance model complexity with generalization ability
52+
53+
Performance metric: score = -log10(MSE)
54+
Higher scores are better. The model will be evaluated on held-out test data.
55+
56+
Strategies to explore:
57+
- Polynomial terms and interactions between variables
58+
- Exponential, logarithmic, and trigonometric functions
59+
- Physical laws and domain-specific relationships
60+
- Feature engineering and transformations
61+
- Regularization through simplicity
62+
num_top_programs: 4
63+
use_template_stochasticity: true
64+
# Memory rendering (from semantic search)
65+
num_similar_parent_best: 3
66+
num_similar_parent_worst: 3
67+
include_similar_parent_worst: true
68+
69+
# Database configuration - ADAPTIVE VERSION
70+
database:
71+
population_size: 70
72+
archive_size: 30
73+
num_islands: 4
74+
elite_selection_ratio: 0.3
75+
76+
# ADAPTIVE EXPLORATION/EXPLOITATION (NEW!)
77+
use_adaptive_search: true
78+
adaptive_window_size: 10 # Track last 10 iterations
79+
adaptive_min_exploration: 0.1 # When improving (10% explore, 80% exploit, 10% random)
80+
adaptive_max_exploration: 0.7 # When stuck (70% explore, 20% exploit, 10% random)
81+
82+
# Static fallback (if use_adaptive_search: false)
83+
exploration_ratio: 0.3
84+
exploitation_ratio: 0.6
85+
86+
# MAP-Elites features
87+
feature_dimensions: ["complexity", "diversity"]
88+
feature_bins: 10
89+
90+
# Evaluator configuration - SAME AS BASE CONFIG
91+
evaluator:
92+
timeout: 90
93+
cascade_evaluation: false
94+
cascade_thresholds: [1.0]
95+
parallel_evaluations: 4
96+
use_llm_feedback: false
97+
98+
# Evolution settings - SAME AS BASE CONFIG
99+
diff_based_evolution: true
100+
allow_full_rewrites: false

0 commit comments

Comments
 (0)