| Crates.io | autoeq-de |
| lib.rs | autoeq-de |
| version | 0.2.52 |
| created_at | 2025-10-05 13:27:31.56601+00 |
| updated_at | 2025-11-20 08:56:48.444801+00 |
| description | Non linear optimisation library with own DE solvers and interface to NLOpt and MetaHeuristics |
| homepage | |
| repository | https://github.com/pierreaubert/sotf |
| max_upload_size | |
| id | 1869055 |
| size | 506,935 |
This crate provides a pure Rust implementation of Differential Evolution (DE) global optimization algorithm with advanced features.
DE/rand/1: x_trial = x_r1 + F * (x_r2 - x_r3)DE/best/1: x_trial = x_best + F * (x_r1 - x_r2)DE/current-to-best/1: Combines current and best vectorsDE/rand/2: Uses five random vectors for mutationuse autoeq_de::{differential_evolution, DEConfig, Strategy, Mutation};
use ndarray::Array1;
// Example objective function (Rosenbrock)
let objective = |x: &Array1<f64>| {
let a = 1.0;
let b = 100.0;
(a - x[0]).powi(2) + b * (x[1] - x[0].powi(2)).powi(2)
};
// Define bounds for 2D problem
let bounds = vec![(-5.0, 5.0), (-5.0, 5.0)];
let config = DEConfig {
strategy: Strategy::Rand1Bin,
maxiter: 1000,
popsize: 50,
mutation: Mutation::Factor(0.8),
recombination: 0.9,
seed: Some(42),
..Default::default()
};
let result = differential_evolution(&objective, &bounds, config);
println!("Best solution: {:?}", result.x);
println!("Best fitness: {}", result.fun);
use autoeq_de::{LinearConstraintHelper, DEConfig};
use ndarray::{Array1, Array2};
// Linear constraint: x1 + x2 <= 1.0
let constraint = LinearConstraintHelper {
a: Array2::from_shape_vec((1, 2), vec![1.0, 1.0]).unwrap(),
lb: Array1::from_vec(vec![f64::NEG_INFINITY]),
ub: Array1::from_vec(vec![1.0]),
};
// Apply to configuration with penalty weight
let mut config = DEConfig::default();
constraint.apply_to(&mut config, 1000.0); // penalty weight
let nonlinear_constraint = |x: &[f64]| -> f64 {
x[0].powi(2) + x[1].powi(2) - 1.0 // circle constraint
};
The crate includes a plot_functions binary for visualizing test functions and optimization traces:
# Plot test functions as contour plots
cargo run --bin plot_functions -- --functions rosenbrock,sphere
# Show optimization traces from CSV files
cargo run --bin plot_functions -- --csv-dir traces/ --show-traces
This crate is part of the AutoEQ ecosystem:
autoeq for filter parameter optimizationautoeq-testfunctions for validationautoeq-iir for audio filter optimizationThe crate includes several example programs demonstrating different DE capabilities:
basic_de: Simple unconstrained optimizationlinear_constraints: Linear constraint handlingnonlinear_constraints: Complex constraint optimizationGPL-3.0-or-later