e

Fugue Evo

Evolution as Bayesian inference — a probabilistic, type-safe evolutionary computation library for Rust.

Crates.io Dev Docs CI License: MIT

Fugue The probabilistic programming library underneath — compose models in direct style and run MH, HMC, and SMC, with its own interactive explorables.

Why Fugue-Evo?

Fugue-evo differentiates itself from traditional GA libraries through several key design principles:

Probabilistic Foundations

Traditional genetic algorithms use heuristic operators, but fugue-evo views evolution through a probabilistic lens:

  • Fitness as Likelihood: Selection pressure maps directly to Bayesian conditioning
  • Learnable Operators: Automatic inference of optimal crossover, mutation, and selection hyperparameters using conjugate priors
  • Trace-Based Evolution: Deep integration with the fugue-ppl probabilistic programming library enables novel trace-based genetic operators

Type Safety

Rust's type system ensures correctness at compile time:

  • Trait-Based Abstraction: The EvolutionaryGenome trait provides a flexible foundation for any genome type
  • Builder Patterns: Algorithm configuration uses type-safe builders that catch misconfigurations at compile time
  • Generic Operators: Selection, crossover, and mutation operators work across genome types with proper type constraints

Production Ready

Built for real-world use:

  • Checkpointing: Save and restore evolution state for long-running optimizations
  • Parallelism: Optional Rayon-based parallel evaluation
  • WASM Support: Run optimizations in the browser with WebAssembly bindings
  • Interactive Evolution: Human-in-the-loop optimization with multiple evaluation modes

Algorithms

Fugue-evo includes several optimization algorithms:

AlgorithmBest ForKey Features
SimpleGAGeneral-purpose optimizationFlexible operators, elitism, parallelism
CMA-ESContinuous optimizationCovariance adaptation, state-of-the-art performance
NSGA-IIMulti-objective optimizationPareto ranking, crowding distance
Island ModelEscaping local optimaParallel populations, migration
EDA/UMDAProbabilistic model buildingDistribution estimation
Interactive GASubjective optimizationHuman feedback integration

Genome Types

Built-in genome representations for different problem domains:

  • RealVector: Continuous optimization (function minimization)
  • BitString: Combinatorial optimization (knapsack, feature selection)
  • Permutation: Ordering problems (TSP, scheduling)
  • TreeGenome: Genetic programming (symbolic regression)

Example

Here's a taste of what optimization looks like with fugue-evo:

use fugue_evo::prelude::*;
use rand::SeedableRng;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut rng = rand::rngs::StdRng::seed_from_u64(42);

    // Define search bounds: 10 dimensions in [-5.12, 5.12]
    let bounds = MultiBounds::symmetric(5.12, 10);

    // Run optimization
    let result = SimpleGABuilder::<RealVector, f64, _, _, _, _, _>::new()
        .population_size(100)
        .bounds(bounds)
        .selection(TournamentSelection::new(3))
        .crossover(SbxCrossover::new(20.0))
        .mutation(PolynomialMutation::new(20.0))
        .fitness(Sphere::new(10))
        .max_generations(200)
        .build()?
        .run(&mut rng)?;

    println!("Best fitness: {:.6}", result.best_fitness);
    Ok(())
}

Getting Started

Ready to dive in? Head to the Installation guide to add fugue-evo to your project, then follow the Quick Start to run your first optimization.

For a deeper understanding of the library's design, explore the Core Concepts section.