20 releases (11 breaking)

0.12.1 Feb 15, 2022
0.11.1 Feb 14, 2022
0.11.0 Nov 16, 2021
0.9.0 Jul 28, 2021

#819 in Algorithms

Download history 1/week @ 2024-01-08 2/week @ 2024-01-15 2/week @ 2024-02-12 4/week @ 2024-02-19 5/week @ 2024-02-26 19/week @ 2024-03-11 15/week @ 2024-03-18 21/week @ 2024-03-25 37/week @ 2024-04-01 10/week @ 2024-04-08 17/week @ 2024-04-15 40/week @ 2024-04-22

105 downloads per month

Apache-2.0

61KB
1K SLoC

simple_optimization

Crates.io lib.rs.io docs

Some simple multi-threaded optimizers.

You could do a random search like:

use std::sync::Arc;
use simple_optimization::{random_search, Polling};
// Our evaluation function takes 3 `f64`s and no additional data `()`.
fn simple_function(list: &[f64; 3], _: Option<Arc::<()>>) -> f64 { list.iter().sum() }
let best = random_search!(
    (0f64..10f64, 5u32..15u32, 10i16..20i16), // Value ranges.
    simple_function, // Evaluation function.
    None, // No additional evaluation data.
    // Every `10ms` we print progress and exit early if `simple_function` return a value less than `19.`.
    Some(Polling::new(true,Some(19.))),
    None, // We don't specify the number of threads to run.
    1000, // Take `1000` samples.
);
assert!(simple_function(&best, None) < 19.);

Which during execution will give an output like:

1000
 500 (50.00%) 00:00:11 / 00:00:47 [25.600657363049734]

Representing:

<Total number of samples>
<Current number of samples> (<Percentage of samples taken>) <Time running> / <ETA> [<Current best value>]

Support

Optimizer Status
Random search
Grid search
Simulated annealing
Bayesian optimization WIP
Gradient descent See my note here
Genetic algorithms No plans
Ant colony optimization No plans
Linear programming No plans

I made this for my own use since the existing libraries I found felt awkward.

Dependencies

~2MB
~38K SLoC