POS_PSO
Highly Configurable Particle Swarm Optimizer implemented in pure Rust
Easily mimimize a cost function across multiple threads
- Multiple optimizations can be run in parallel with Independant Swarms
- or Swarms can periodically share best-known locations in the search space with Collaborative Swarms
Motion dynamics are loosly based on Matlab's Particle Swarm Algorithm
Optimizer takes a closure with the following header as the cost function:
move |x: &|
- The input slice-array represents a point in the N dimensional optimization space
- The returned cost is used to navigate the search space to locate a minimum
- currently only supports f64, but future updates may allow more generic cost-functions
Some Examples to get started:
Single-Threaded Example (Single Swarm)
- Use the default independant swarm configuration (good place to start, but you may want to define your own based on your use case)
- Search Space Bounds and Max Velocities still must be defined in a JobConfig object
- Single-Swarm may be the fastest performing option for high-end intel processors
extern crate pos_pso;
use ;
Multi-Threaded Example* Use 4 collaborative swarms with fewer particles in each)
- A custom swarm configuration is defined with motion coefficients and a record-sharing period
- This may be the fastest performing option on high-end AMD processors
let num_variables = 5;
// Define a cost function to minimize:
//data captured by closure
let mins = vec!;
let coeffs = vec!;
//cost function closure must take a &[f64] and return f64
let cost_function = move |point: &| ;
// Create a PSO Configuration:
let pso_config = new;
// Create a PSO:
let pso = PSO new;
// Create a Job Configuration:
let job_config = new;
// Create a custom Swarm Configuration:
//collaborative swarms will share information with eachother about best known locations in the search space
let swarm_config = new_collaborative;
// Minimize cost function:
//use minimize to optimize with a custom SwarmConfig
let min = pso.minimize;
println!;
Advanced Example
- Use a group of 8 independant swarms to minimize the same cost function with different swarm parameters
- This example shows how to use a SwarmConfigDistribution where swarm-behavior coefficients are sampled from a user defined distribution
- All 8 swarms run in parallel on seperate threads (the lowest cost and best location are returned after all threads have finished)
extern crate pos_pso;
use ;