cmaes

A Rust implementation of the CMA-ES optimization algorithm. It is used to minimize the value of an objective function and performs well on high-dimension, non-linear, non-convex, ill-conditioned, and/or noisy problems. See this paper for details on the algorithm itself. This library is based on the linked paper and the pycma implementation.

Dependencies

cmaes uses some external libraries, so the following dependencies are required:

Dependencies may differ depending on the selected LAPACK implementation. Building is currently only supported on Linux (see issue #4).

Quick Start

Add this to your Cargo.toml:

[dependencies] cmaes = "0.1.0"

The LAPACK implementation used may be selected through Cargo features (see Cargo.toml). netlib is built from source by default.

Then, to optimize a function: ```rust use cmaes::{CMAESOptions, DVector, PlotOptions};

let sphere = |x: &DVector| x.iter().map(|xi| xi.powi(2)).sum();

let dim = 10; let mut cmaesstate = CMAESOptions::new(dim) .initialmean(vec![1.0; dim]) .enableprinting(200) .enableplot(PlotOptions::new(0, false)) .build(sphere) .unwrap();

let maxgenerations = 20000; let result = cmaesstate.run(max_generations);

cmaesstate.getplot().unwrap().savetofile("plot.png", true).unwrap(); ```

The produced plot will look like this:

For more information, see the documentation and examples.

Contributing

Contributions are welcome! You can contribute by reporting any bugs or issues you have with the library, adding documentation, or opening pull requests.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

Licensed under either of

Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.