[][src]Struct simplers_optimization::Optimizer

pub struct Optimizer<'f_lifetime, CoordFloat: Float, ValueFloat: Float> { /* fields omitted */ }

Stores the parameters and current state of a search.

  • ValueFloat is the float type used to represent the evaluations (such as f64)
  • CoordFloat is the float type used to represent the coordinates (such as f32)

Methods

impl<'f_lifetime, CoordFloat: Float, ValueFloat: Float> Optimizer<'f_lifetime, CoordFloat, ValueFloat>[src]

pub fn new(
    f: &'f_lifetime impl Fn(&[CoordFloat]) -> ValueFloat,
    input_interval: &[(CoordFloat, CoordFloat)],
    should_minimize: bool
) -> Self
[src]

Creates a new optimizer to explore the given search space with the iterator interface.

Takes a function, a vector of intervals describing the input and a boolean describing wether it is a minimization problem (as oppozed to a miximization problem). Each cal to the .next() function (cf iterator trait) will run an iteration of search and output the best result so far.

Warning: In d dimenssions, this function will perform d+1 evaluation (call to f) for the initialisation of the search (those should be taken into account when counting iterations).

let f = |v:&[f64]| v[0] * v[1];
let input_interval = vec![(-10., 10.), (-20., 20.)];
let should_minimize = true;

// runs the search for 30 iterations
// then waits until we find a point good enough
// finally stores the best value so far
let (min_value, coordinates) = Optimizer::new(&f, &input_interval, should_minimize)
                                         .skip(30)
                                         .skip_while(|(value,coordinates)| *value > 1. )
                                         .next().unwrap();

println!("min value: {} found in [{}, {}]", min_value, coordinates[0], coordinates[1]);

pub fn set_exploration_depth(self, exploration_depth: usize) -> Self[src]

Sets the exploration depth for the algorithm, useful when using the iterator interface.

exploration_depth represents the number of splits we can exploit before requiring higher-level exploration. As long as one stays in a reasonable range (5-10), the algorithm should not be very sensible to the parameter :

  • 0 represents full exploration (similar to grid search)
  • high numbers focus on exploitation (no need to go very high)
  • 5 appears to be a good default value

WARNING: this function should not be used before after an iteration (as it will not update the score of already computed points for the next iterations which will degrade the quality of the algorithm)

let f = |v:&[f64]| v[0] * v[1];
let input_interval = vec![(-10., 10.), (-20., 20.)];
let should_minimize = true;

// sets exploration_depth to be very greedy
let (min_value_greedy, _) = Optimizer::new(&f, &input_interval, should_minimize)
                                         .set_exploration_depth(20)
                                         .skip(100)
                                         .next().unwrap();

// sets exploration_depth to focus on exploration
let (min_value_explore, _) = Optimizer::new(&f, &input_interval, should_minimize)
                                         .set_exploration_depth(0)
                                         .skip(100)
                                         .next().unwrap();

println!("greedy result : {} vs exploration result : {}", min_value_greedy, min_value_explore);

pub fn maximize(
    f: &'f_lifetime impl Fn(&[CoordFloat]) -> ValueFloat,
    input_interval: &[(CoordFloat, CoordFloat)],
    nb_iterations: usize
) -> (ValueFloat, Box<[CoordFloat]>)
[src]

Self contained optimization algorithm.

Takes a function to maximize, a vector of intervals describing the input and a number of iterations.

let f = |v:&[f64]| v[0] + v[1];
let input_interval = vec![(-10., 10.), (-20., 20.)];
let nb_iterations = 100;

let (max_value, coordinates) = Optimizer::maximize(&f, &input_interval, nb_iterations);
println!("max value: {} found in [{}, {}]", max_value, coordinates[0], coordinates[1]);

pub fn minimize(
    f: &'f_lifetime impl Fn(&[CoordFloat]) -> ValueFloat,
    input_interval: &[(CoordFloat, CoordFloat)],
    nb_iterations: usize
) -> (ValueFloat, Box<[CoordFloat]>)
[src]

Self contained optimization algorithm.

Takes a function to minimize, a vector of intervals describing the input and a number of iterations.

let f = |v:&[f64]| v[0] * v[1];
let input_interval = vec![(-10., 10.), (-20., 20.)];
let nb_iterations = 100;

let (min_value, coordinates) = Optimizer::minimize(&f, &input_interval, nb_iterations);
println!("min value: {} found in [{}, {}]", min_value, coordinates[0], coordinates[1]);

Trait Implementations

impl<'f_lifetime, CoordFloat: Float, ValueFloat: Float> Iterator for Optimizer<'f_lifetime, CoordFloat, ValueFloat>[src]

implements iterator for the Optimizer to give full control on the stopping condition to the user

type Item = (ValueFloat, Box<[CoordFloat]>)

The type of the elements being iterated over.

fn next(&mut self) -> Option<Self::Item>[src]

runs an iteration of the optimization algorithm and returns the best result so far

Auto Trait Implementations

impl<'f_lifetime, CoordFloat, ValueFloat> !Send for Optimizer<'f_lifetime, CoordFloat, ValueFloat>

impl<'f_lifetime, CoordFloat, ValueFloat> !Sync for Optimizer<'f_lifetime, CoordFloat, ValueFloat>

impl<'f_lifetime, CoordFloat, ValueFloat> Unpin for Optimizer<'f_lifetime, CoordFloat, ValueFloat> where
    CoordFloat: Unpin,
    ValueFloat: Unpin

impl<'f_lifetime, CoordFloat, ValueFloat> !UnwindSafe for Optimizer<'f_lifetime, CoordFloat, ValueFloat>

impl<'f_lifetime, CoordFloat, ValueFloat> !RefUnwindSafe for Optimizer<'f_lifetime, CoordFloat, ValueFloat>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]