Expand description
§genoxide
Optimization for Rust (and Python): evolutionary, local, gradient-based, Bayesian and multi-objective methods in one library. A seed gives the same results, to the bit, on every platform and thread count, parallel or not.
| Problem | Method |
|---|---|
| Yes / no choices, integers, orders (subsets, schedules, tours) | the genetic algorithm Ga, LocalSearch |
| Real numbers in a box, no gradient | Cmaes, De, Pso, Es, NelderMead |
| Smooth functions with a gradient | Lbfgsb, and FirstOrder (Adam, momentum) for millions of variables |
| Many variables, few inequality constraints, with gradients | Mma (MMA and GCMMA) |
| An expensive function: tens to a few hundred evaluations, in batches or asynchronously, with constraints, of real or integer genes | Bo, Bayesian optimization, with the Gaussian processes of model::gp |
| A smooth problem solved in stages (a smoothing, sharpness or penalty changed step by step) | Continuation around a local method, its state kept |
| Several objectives at once | Nsga2, Nsga3, Moead, SmsEmoa |
| Programs and formulas | gp: tree genetic programming |
| A neural network’s weights | nn with Cmaes |
For AI coding assistants, AGENTS.md is a complete guide in one page, with a program for every method, each run in CI.
Alpha, pre-1.0: the API changes between 0.x versions. See the roadmap for what is planned.
use genoxide::prelude::*;
// OneMax: find the genome with the most ones
let ga = Ga::builder(Binary::new(100)?)
.population_size(100)
.select(Tournament::new(3)?)
.crossover(UniformCrossover::new())
.mutate(BitFlip::per_gene(0.01)?)
.seed(42)
.build()?;
let outcome = Engine::new(ga, |genome: &Bits| genome.count_ones() as f64)
.stop_when(Stop::target(100.0).or(Stop::generations(1_000)))
.run()?;
println!("best: {:?} after {} generations", outcome.best_fitness(), outcome.generations());The building blocks:
Error: all errors: invalid settings are errors, not panicsStreamRng: portable, seedable random numbers with independent streamsFitnessandObjective: totally ordered fitness values, with an invalid state and constraint violations (constraint, Deb’s feasibility rules)genome: genomes and the spaces they live in, e.g. bit-packedBinaryIndividualandPopulation: genomes with their fitness and ageoperator: selection, crossover and mutationalgorithm: algorithms as ask / tell state machines: the genetic algorithmGa,LocalSearch(hill climbing, simulated annealing, tabu search), evolution strategiesEs, CMA-ESCmaes, differential evolutionDe, particle swarm optimizationPso, and the island modelIslands, andSteadyGafor asynchronous evaluationEngine: runs an algorithm with stop conditions, parallel or batch evaluation and cancellation;AsyncEngineevaluates asynchronouslygradient: gradients for gradient-based methods, supplied with the fitness (Differentiable) or by finite differencesgp: tree genetic programming, strongly typed: programs and formulas as genomes, with subtree crossover and mutationnn: neural networks whose weights are a genome, a multilayer perceptron and an Elman recurrent network, for neuroevolutionmulti: multi-objective optimization: NSGA-II, NSGA-III, SPEA2, MOEA/D, SMS-EMOA, theMultiEngine, Pareto dominance and non-dominated sortingobserver: statistics, hall of fame, progress lines and custom callbacksproblems: single-objective test problems from the literature, with their bounds, known optima and references, and control tasks that balance poles on a cartprelude: everything above in one importmath:sin,cos,exp,powf,powiand the like, the same to the bit on every platform, for fitness functions that must give the same results everywhere
Cargo features:
parallel(default): parallel fitness evaluation with rayontracing: a span per run, an event per generation and one at the end, with the targetgenoxide, from the three enginesserde:SerializeandDeserializefor algorithms and their parts, andcheckpoint, to save a run and resume it exactlycli: thegenoxideprogram, which runs an optimization described in a TOML or JSON file with any program as the fitness function, see docs/cli.md
For Python, the genoxide package on PyPI runs the
algorithms with fitness functions in Python and numpy. Its source is in
python/.
Re-exports§
pub use algorithm::Algorithm;pub use algorithm::Ga;pub use engine::Engine;pub use engine::Evaluated;pub use engine::Outcome;pub use engine::Stop;pub use engine::StopReason;pub use error::Error;pub use error::Result;pub use fitness::Fitness;pub use fitness::Objective;pub use individual::Individual;pub use population::Population;pub use rng::StreamRng;
Modules§
- algorithm
- Algorithms as ask / tell state machines.
- checkpoint
serde - Checkpoints: an algorithm saved during a run, to resume the run later with exactly the results it would have had without the interruption.
- constraint
- Constraint handling: measuring constraint violations, and penalty functions.
- engine
- Running an algorithm: fitness evaluation, stop conditions, observers and cancellation.
- error
- Errors returned by genoxide.
- fitness
- Fitness values and the optimization objective.
- genome
- Genomes (the encoded solutions) and representations (the spaces they live in).
- gp
- Tree genetic programming, strongly typed: programs and formulas as genomes.
- gradient
- Gradients: supplied with the fitness, or estimated by finite differences.
- individual
- A genome with its fitness and age.
- math
- Portable math: the same bits on every platform, at native speed.
- model
- Surrogate models: cheap approximations of an expensive function, fitted to its evaluations.
- multi
- Multi-objective optimization: solutions scored on several objectives at once, and the Pareto front of the best trade-offs between them.
- neat
- NEAT, NeuroEvolution of Augmenting Topologies (Stanley and Miikkulainen 2002): networks whose structure evolves with their weights, from minimal networks up.
- nn
- Neural networks whose weights are a genome: a multilayer perceptron and an Elman recurrent network, for neuroevolution with a fixed topology.
- observer
- Observers: statistics, hall of fame and custom callbacks, notified after every generation.
- operator
- Genetic operators: selection, crossover and mutation.
- population
- A population of individuals.
- prelude
- Everything needed for most programs, in one import.
- problems
- Single-objective test problems: fitness functions with their search space, their known optimum and the paper that defines them.
- rng
- Portable, seedable random number generation with independent streams.