Skip to content

Repository files navigation

Evolving Evolutionary Algorithms with ShinkaEvolve

Overview

This project demonstrates a novel application of ShinkaEvolve to the meta-problem of evolving evolutionary algorithms themselves. Specifically, we use ShinkaEvolve's LLM-driven evolution to discover novel and effective selection strategies and diversity maintenance mechanisms for evolutionary algorithms.

Why This Is Interesting

  1. Meta-Level Evolution: Using evolution to improve evolution itself - a fascinating recursive application
  2. Novel Application Domain: Extends ShinkaEvolve beyond ML and optimization to algorithmic discovery
  3. Practical Value: Could discover selection strategies that outperform classical methods
  4. Scientific Insight: Reveals what makes evolutionary algorithms effective through automated discovery

The Problem

Evolutionary algorithms (EAs) rely heavily on their selection mechanism - how they choose which solutions become parents of the next generation. Classical selection strategies include:

  • Fitness-proportionate (roulette wheel)
  • Tournament selection
  • Rank-based selection
  • Truncation selection

Each has trade-offs between:

  • Exploitation (focusing on best solutions)
  • Exploration (maintaining diversity)
  • Convergence speed vs solution quality
  • Generalization across different problem types

The challenge: Can we discover novel selection strategies that perform better than these classical approaches?

Our Approach

What Gets Evolved

We evolve two key functions in initial.py:

  1. select_parents(): The selection strategy that chooses which solutions reproduce

    • Input: population, fitness values, generation info
    • Output: selected parent solutions
    • Baseline: Simple fitness-proportionate selection
  2. apply_diversity_mechanism(): Diversity maintenance strategy

    • Input: population, fitness values, generation info
    • Output: modified population (with diversity adjustments)
    • Baseline: No diversity mechanism (passthrough)

How We Test It

The evolved EA is evaluated on multiple benchmark optimization functions:

Function Characteristics Difficulty
Sphere Simple, unimodal, smooth Easy
Rosenbrock Narrow valley, curved ridge Medium
Rastrigin Many local optima, highly multimodal Hard
Ackley Many local minima, deep global minimum Hard

Each evolved strategy is tested across:

  • Multiple problem dimensions (5D, 8D, 10D, 15D)
  • Different population sizes (30-60 individuals)
  • Various generation budgets (50-120 generations)
  • Multiple random seeds for statistical robustness

Fitness Metrics

Performance is measured by a combined score that balances multiple objectives:

Combined Score =
    1.0 × mean_fitness           (primary: solution quality)
  + 0.3 × convergence_bonus      (faster is better)
  + 0.1 × diversity_bonus        (maintain diversity)
  - 0.05 × consistency_penalty   (penalize high variance)

Project Structure

examples/evolve_ea/
├── README.md                 # This file
├── initial.py               # Baseline EA with evolvable selection
├── evaluate.py              # Evaluation script (integrates with ShinkaEvolve)
├── run_evo.py              # Launch script for evolution
├── standalone_test.py       # Test without full ShinkaEvolve install
├── test_initial.py         # Basic functionality tests
└── improved_example.py      # Example of a manually improved strategy

Running the Experiments

Prerequisites

  1. Python 3.10+ (required by ShinkaEvolve)
  2. ShinkaEvolve installed (pip install -e . from project root)
  3. API keys for LLM providers (OpenAI, Anthropic, etc.)

Quick Test (Without ShinkaEvolve)

Test the baseline implementation:

cd examples/evolve_ea
python3 standalone_test.py

This runs the baseline EA on 3 benchmark functions and shows performance metrics.

Full Evolution Experiment

Option 1: Using the Launch Script

cd examples/evolve_ea
python3 run_evo.py

Option 2: Using Hydra Configuration

# From project root
shinka_launch variant=evolve_ea_experiment

Option 3: Custom Configuration

shinka_launch \
    task=evolve_ea \
    database=island_small \
    evolution=small_budget \
    evo_config.num_generations=30 \
    evo_config.llm_models='["gpt-4-turbo-preview"]'

Configuration Options

The experiment can be customized via configs/variant/evolve_ea_experiment.yaml:

Evolution Parameters:

  • num_generations: Total evolution cycles (default: 30)
  • max_parallel_jobs: Parallel evaluations (default: 2)
  • patch_types: ["diff", "full"] - mutation strategies
  • llm_models: LLM models to use for code generation

Population Management:

  • num_islands: Parallel subpopulations (default: 2)
  • archive_size: Elite programs per island (default: 20)
  • parent_selection_strategy: "power_law", "weighted", or "beam_search"
  • exploitation_ratio: Balance explore/exploit (default: 0.3)

Diversity Mechanisms:

  • code_embed_sim_threshold: Reject similar code (default: 0.85)
  • max_novelty_attempts: Rejection sampling tries (default: 2)
  • migration_interval: Cross-island migration frequency (default: 10)

Understanding the Results

Output Structure

After running, you'll find:

outputs/
└── shinka_evolve_ea_ea_evolution/
    ├── evolution_database.db          # SQLite database with all programs
    ├── programs/                      # Generated program files
    │   ├── gen_0_prog_0.py
    │   ├── gen_1_prog_0.py
    │   └── ...
    ├── results/                       # Evaluation results
    │   ├── gen_0_prog_0/
    │   │   ├── results.json
    │   │   └── metrics.pkl
    │   └── ...
    └── meta_recommendations/          # High-level insights from LLM

Analyzing Results

  1. Best Program: Check evolution_database.db for highest scoring program
  2. Fitness History: Track improvement over generations
  3. Code Diff: Compare evolved code to baseline
  4. Performance Metrics: See results.json for detailed metrics

Visualizing Evolution

Use ShinkaEvolve's WebUI:

shinka_visualize --port 8888 --open

Features:

  • Real-time fitness tracking
  • Genealogy tree of programs
  • Code diff viewer
  • Population diversity plots

Example Results

Baseline Performance

The simple fitness-proportionate selection baseline achieves:

Mean Best Fitness:    -29.81 (±28.93)
Mean Convergence:     97.92% of generations needed
Mean Diversity:       0.338
Combined Score:       -31.22

Strengths:

  • Simple and interpretable
  • Works reasonably on easy problems (Sphere)

Weaknesses:

  • Slow convergence (uses nearly all generations)
  • High variance across problems
  • Struggles with multimodal landscapes (Rastrigin)
  • No explicit diversity maintenance

Expected Improvements

ShinkaEvolve-evolved strategies could discover:

  1. Adaptive Selection Pressure

    • Start with exploration (low pressure)
    • Gradually increase exploitation
    • Based on generation progress or convergence indicators
  2. Hybrid Strategies

    • Combine tournament and fitness-proportionate
    • Switch based on problem characteristics
    • Use fitness distribution statistics
  3. Diversity-Aware Selection

    • Penalize similar solutions
    • Maintain population spread
    • Balance fitness and novelty
  4. Problem-Adaptive Mechanisms

    • Detect landscape type (multimodal vs unimodal)
    • Adjust strategy dynamically
    • Use convergence rate as feedback

Implementation Details

Evolvable Code Blocks

The code between # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END markers is evolved:

# EVOLVE-BLOCK-START
def select_parents(population, fitness, num_parents, generation, max_generations):
    # This code will be modified by LLMs
    # ...
    return selected_parents

def apply_diversity_mechanism(population, fitness, generation, max_generations):
    # This code will be modified by LLMs
    # ...
    return population, fitness
# EVOLVE-BLOCK-END

Everything else remains fixed, ensuring:

  • Consistent evaluation framework
  • Fair comparison across strategies
  • No changes to mutation/crossover operators

Mutation Strategies

ShinkaEvolve uses two types of code mutations:

  1. Diff Patches (60%):

    • Small, targeted modifications
    • Search-and-replace format
    • Good for refining existing strategies
  2. Full Rewrites (40%):

    • Complete algorithm redesigns
    • 5 prompt variants (different, motivated, structural, parametric)
    • Good for exploration

LLM Guidance

The system prompt provides:

  • Domain knowledge about evolutionary computation
  • Successful selection strategies to consider
  • Information about benchmark functions
  • Guidelines for creating effective strategies

This enables the LLM to make informed, theoretically sound modifications.

Advanced Features

Meta-Recommendations

Every 8 programs, ShinkaEvolve generates high-level insights:

Meta-Recommendation Example:
"Strategies using adaptive selection pressure (increasing over generations)
show 23% better performance on multimodal problems. Consider exploring
tournament selection variants with dynamic tournament size."

Island Model

The population is divided into 2 islands that evolve independently:

  • Prevents premature convergence to local optima
  • Different islands explore different strategies
  • Best programs migrate between islands every 10 generations

Novelty Filtering

Code similarity checking prevents generating near-duplicates:

  • Embeddings computed for all code blocks
  • New code rejected if >85% similar to existing
  • Encourages exploration of diverse strategies

Extending This Work

Ideas for Further Exploration

  1. Co-evolve Multiple Components

    • Selection + mutation rate
    • Selection + crossover strategy
    • Full EA pipeline evolution
  2. Multi-Objective Optimization

    • Optimize for both speed and quality
    • Pareto front of EA strategies
    • User-selectable trade-offs
  3. Transfer Learning

    • Train on simple problems
    • Test on complex real-world problems
    • Measure generalization ability
  4. Meta-Learning

    • Learn to select EA strategy based on problem features
    • Automatic algorithm configuration
    • Portfolio of specialized strategies
  5. Beyond Function Optimization

    • Combinatorial problems (TSP, scheduling)
    • Evolutionary robotics
    • Neural architecture search

Modifying the Task

To test on different problems:

  1. Add new benchmark functions in initial.py:

    def my_function(x):
        return -complex_calculation(x)
  2. Update test configs in evaluate.py:

    {
        'benchmark_name': 'my_function',
        'dim': 20,
        'seed': 42,
        'pop_size': 100,
        'num_generations': 200,
    }
  3. Adjust fitness aggregation if needed

Technical Insights

Why This Works

  1. Rich Search Space: Selection strategies have many design choices
  2. Clear Objective: Performance on benchmarks is unambiguous
  3. Fast Evaluation: Each EA run takes seconds to minutes
  4. Generalization: Multiple test problems ensure robustness
  5. LLM Knowledge: GPT-4 knows evolutionary computation theory

Challenges

  1. Evaluation Cost: Each strategy requires multiple EA runs
  2. Variance: Stochastic algorithms need many seeds
  3. Overfitting: Risk of specializing to specific benchmarks
  4. Complexity: Selection interacts with other EA components

Design Decisions

  • Why fitness-proportionate baseline?: Simple, interpretable, room for improvement
  • Why these benchmarks?: Standard in EC literature, diverse landscapes
  • Why 6 test runs?: Balance between robustness and evaluation cost
  • Why evolve selection separately?: Focused problem, clearer attribution

Related Work

Evolutionary Algorithm Design

  • Automated algorithm configuration (SMAC, irace)
  • Hyper-heuristics: Evolving heuristics for optimization
  • Meta-evolutionary algorithms: EAs that evolve EA parameters

LLMs for Algorithm Design

  • AlphaEvolve: Google's Gemini-powered algorithm evolution
  • FunSearch: Discovering mathematical algorithms with LLMs
  • AI Scientist v1/v2: Automated scientific discovery

This Project's Novelty

  • Open-source and accessible: Uses ShinkaEvolve framework
  • Focuses on selection mechanisms: Often overlooked in AutoML
  • Rigorous evaluation: Multiple benchmarks, statistical testing
  • Transferable methodology: Can apply to other EA components

Citation

If you use this work, please cite:

@misc{evolve_ea_shinka2025,
  title={Evolving Evolutionary Algorithms with ShinkaEvolve},
  author={[Your Name]},
  year={2025},
  note={Extension of ShinkaEvolve framework for EA strategy discovery}
}

@article{lange2025shinka,
  title={ShinkaEvolve: Towards Open-Ended And Sample-Efficient Program Evolution},
  author={Lange, Robert Tjarko and Imajuku, Yuki and Cetin, Edoardo},
  journal={arXiv preprint arXiv:2509.19349},
  year={2025}
}

Acknowledgments

This project builds on:

  • ShinkaEvolve by Sakana AI
  • Classical evolutionary computation research
  • The broader AutoML and meta-learning communities

Contact & Contributions

For questions, suggestions, or contributions:

  • Open an issue on GitHub
  • Submit a pull request
  • Contact: [your contact info]

Note: This is a research prototype. Evolved strategies should be validated on additional problems before production use.

About

Using AI to discover better evolutionary algorithms through automated code evolution with ShinkaEvolve

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages