LLaMEA: A Large Language Model Evolutionary Algorithm for Automatically Generating Metaheuristics

Niki van Stein, Thomas BäckarXiv 2024 · OpenReview

TL;DR

This paper introduces LLaMEA, a novel framework that uses Large Language Models (LLMs) within an evolutionary loop to automatically generate and optimize metaheuristic algorithms for complex optimization problems. LLaMEA successfully creates novel algorithms that outperform state-of-the-art methods on the BBOB benchmark, demonstrating the potential of LLMs for automated algorithm design.

What Problem Does This Paper Address?

Designing effective optimization algorithms, particularly metaheuristics inspired by natural phenomena, is a laborious and expert-driven process. While many such algorithms exist, developing novel ones often requires deep domain knowledge and extensive experimentation. Furthermore, existing modular frameworks for algorithm design, while powerful, still rely on expert-defined components and design spaces. This paper addresses the challenge of automating the discovery and optimization of metaheuristic algorithms, aiming to reduce reliance on human expertise and explore a broader algorithmic design space. Specifically, they focus on generating algorithms for black-box, continuous optimization problems.

Methods

The core of the proposed method is the LLaMEA (Large Language Model Evolutionary Algorithm) framework. LLaMEA combines an LLM (like GPT-4) with an evolutionary computation approach. Here's how it works:

  • Initialization: The process begins with a detailed task prompt specifying the optimization problem, desired output format (Python code), and constraints. An initial, simple random search algorithm is provided as an example.
  • Evolutionary Loop:
    • Generation: The LLM is prompted to generate a new algorithm (offspring) based on the task description and feedback from previous iterations. This generation process can be seen as a "mutation" or "redesign" step.
  • Evaluation: The generated algorithm's code is dynamically loaded and evaluated on a benchmark suite (BBOB) using the IOHprofiler tool. Performance metrics like the Area Over the Convergence Curve (AOCC) are calculated.
  • Feedback: Performance metrics, along with any runtime errors, are fed back to the LLM to guide the generation of the next algorithm.
  • Selection: Two strategies are employed:
  • (1+1)-strategy (Elitist): The best-performing algorithm found so far is used to construct the prompt for the next generation.
  • (1,1)-strategy (Non-Elitist): The most recently generated algorithm is used for prompt construction.
  • Automated Refinement: LLaMEA iteratively refines algorithms by leveraging the LLM's ability to understand code, performance feedback, and error messages. The LLM can adjust hyperparameters, introduce new logic, or even redesign algorithms.

Datasets

The primary dataset used for evaluation is the Black-Box Optimization Benchmark (BBOB) suite. This suite consists of 24 noiseless functions categorized into five groups, designed to represent a diverse range of optimization landscapes. The authors use standard instances of these functions and also explore their performance on higher dimensions (10D and 20D) even though the algorithms were primarily generated and optimized in 5D.

Key Insights and Ideas

  • LLMs as Algorithm Designers: The most significant insight is that LLMs can be effectively leveraged not just to write code, but to design novel, high-performing optimization algorithms. This moves beyond simple code generation to algorithmic innovation.
  • Evolutionary Loop for LLMs: Integrating LLMs into an evolutionary loop allows for iterative improvement and automated refinement, mimicking biological evolution to discover better solutions. The feedback mechanism is crucial for guiding this process.
  • Automated Discovery of State-of-the-Art Algorithms: LLaMEA demonstrated the ability to generate algorithms that outperform established, hand-crafted algorithms like CMA-ES and Differential Evolution on specific benchmarks. This suggests that LLMs can uncover effective algorithmic structures that might be missed by human experts.
  • Generalization Beyond Training Dimensions: The generated algorithms showed competitive performance on higher dimensional instances of the BBOB functions, even though they were trained and optimized in 5D. This hints at a degree of generalization, though not always superior to specialized algorithms in higher dimensions.
  • LLM's Understanding of Code and Performance: The LLM's ability to interpret performance metrics and error messages, and then translate that into code modifications, is a key enabler of the framework.

Key Results

  • LLaMEA generated multiple novel algorithms that outperformed state-of-the-art algorithms (CMA-ES and Differential Evolution) on the 5-dimensional BBOB benchmark.
  • One generated algorithm, ERADS_QuantumFluxUltraRefined, achieved better performance than the optimized CMA-ES baseline in 5D.
  • The generated algorithms also showed competitive performance on 10D and 20D instances of the BBOB functions, though they didn't always surpass specialized algorithms in these higher dimensions.
  • The framework successfully generated algorithms that were robust to runtime errors, with the LLM able to refine code based on error feedback.
  • The LLM demonstrated the ability to both tune hyperparameters and introduce new algorithmic logic (e.g., different mutation strategies).

Limitations and Future Work

  • Prompt Dependency: The quality and structure of the prompts significantly influence the LLM's output, potentially introducing biases or limiting diversity.
  • Execution Reliability: Dynamically generated code can be prone to runtime errors, which can affect evaluation. While LLaMEA handles this, it's an ongoing challenge.
  • Computational Cost: Querying large LLMs can be computationally expensive, especially for extensive optimization runs.
  • Scalability to Higher Dimensions: While some generalization was observed, the generated algorithms did not consistently scale to higher dimensions as well as specialized methods.
  • Future Work: The authors suggest expanding LLaMEA to support broader evolutionary strategies (e.g., (μ+λ)-EA), using multiple LLMs in parallel, and applying the methodology to other algorithm classes (e.g., Bayesian optimization, surrogate-assisted methods). They also highlight the potential for LLMs to generate more complex, multi-objective optimization algorithms.

Summary updated

Abstract

Large Language Models (LLMs) such as GPT-4 have demonstrated their ability to understand natural language and generate complex code snippets. This paper introduces a novel Large Language Model Evolutionary Algorithm (LLaMEA) framework, leveraging GPT models for the automated generation and refinement of algorithms. Given a set of criteria and a task definition (the search space), LLaMEA iteratively generates, mutates and selects algorithms based on performance metrics and feedback from runtime evaluations. This framework offers a unique approach to generating optimized algorithms without requiring extensive prior expertise. We show how this framework can be used to generate novel black-box metaheuristic optimization algorithms automatically. LLaMEA generates multiple algorithms that outperform state-of-the-art optimization algorithms (Covariance Matrix Adaptation Evolution Strategy and Differential Evolution) on the five dimensional black box optimization benchmark (BBOB). The algorithms also show competitive performance on the 10- and 20-dimensional instances of the test functions, although they have not seen such instances during the automated generation process. The results demonstrate the feasibility of the framework and identify future directions for automated generation and optimization of algorithms via LLMs.
BibTeX
@misc{stein2024llamea,
  author = {Niki van Stein and Thomas Bäck},
  title = {{LLaMEA: A Large Language Model Evolutionary Algorithm for Automatically Generating Metaheuristics}},
  year = {2024},
  eprint = {2405.20132},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.20132},
}
Figure