PSO
Easy and Efficient Particle Swarm Optimizer in Rust
Features
- Efficient Multi-Threaded optimization
- Simple API with many optional parameters to configure
- Minimizes an N dimensional objective function defined as a closure
- Lots of fanciness under the hood to avoid local minima traps
Examples
Simple
// set up a PSO with 8 default swarms
let pso = PSO default;
// set up the stop condition and search space with a JobConfig
let mut jc = new; // search a 5 variable space
jc.exit_cost; // stop optimizing when the objective cost reaches 10e-10
jc.variable_bound; // constrain the 5D search space to (-5, 5) along all dimensions
// create a simple objective function
let obj = ;
// search for the minimum
let min = pso.run_job_fn;
assert!;
for x in min.1
Advanced
// define a swarm configuration
let mut sc = new;
sc.synergic_behavior; // collaborate with other swarms every 100 iterations using a global-coefficient of 0.4
sc.motion_coefficients; // use custom motion coefficients
sc.num_particles; // put 256 particles in each swarm
// set up a PSO with 8 swarms using the above SwarmConfig
let pso = PSO from_swarm_config;
// set up the stop condition and search space with a JobConfig
let mut jc = new;
jc.max_iter_and_exit_cost; // stop after the first of these conditions is met
jc.variable_bounds;
jc.update_console; // update the console with the current minimum every 100 iterations
// create a simple objective function using some external data
let mins = ;
let obj = move |x_vec: &| ;
// search for the minimum
let min = pso.run_job_fn;
assert!;
for in min.1.iter.enumerate