Struct multivariate_optimization::optimize::Solver
source · pub struct Solver<S, C> { /* private fields */ }Expand description
Parallel solver for multidimensional problems.
Usual workflow:
Solver::newSolver::set_speed_factor- Pass result of
Solver::random_specimenstoSolver::extend_specimens - In a loop:
- Inspect first element (or more elements) of
Solver::specimens, e.g. for a break condition - Pass result of
Solver::recombined_specimenstoSolver::replace_worst_specimens
- Inspect first element (or more elements) of
- Extract best specimen, e.g. using
Solver::into_specimen
See module level documentation for a code example.
Implementations§
source§impl<S, C> Solver<S, C>
impl<S, C> Solver<S, C>
sourcepub fn set_division_count(&mut self, division_count: usize)
pub fn set_division_count(&mut self, division_count: usize)
Simplify calculation by dividing dimensions into a given number of groups.
Divides dimensions into (almost) equally sized groups when calculating covariances to reduce computation time. The number of groups is given as an integer.
See Solver::set_speed_factor for a high-level interface.
sourcepub fn set_speed_factor(&mut self, speed_factor: f64)
pub fn set_speed_factor(&mut self, speed_factor: f64)
Simplify calculation by dividing dimensions according to speed factor.
This method is a high-level interface for
Solver::set_division_count.
Uses a speed_factor to divide dimensions into (almost) equally sized
groups when calculating covariances to reduce computation time. Higher
speed factors generally result in faster (but possibly inaccurate)
calculation.
Speed factors range from 0.0 to 1.0, however, a factor greater than
0.75 is not recommended due to the introduced overhead.
sourcepub fn set_max_division_size(&mut self, max_division_size: usize)
pub fn set_max_division_size(&mut self, max_division_size: usize)
Simply calculation by dividing dimensions into groups of specified maximum size.
This method is an alternative interface for
Solver::set_division_count where the maximum size of each division
is specified.
See Solver::set_speed_factor for a high-level interface.
sourcepub fn division_count(&self) -> usize
pub fn division_count(&self) -> usize
Number of groups into which dimensions are split when calculating covariances.
sourcepub fn min_population(&self) -> usize
pub fn min_population(&self) -> usize
Minimum required population.
The number depends on the number of dimensions and the number of groups into which the dimensions are split when calculating covariances.
source§impl<S, C> Solver<S, C>where
C: Fn(Vec<f64>) -> S + Sync,
impl<S, C> Solver<S, C>where C: Fn(Vec<f64>) -> S + Sync,
sourcepub fn new(search_space: Vec<SearchRange>, constructor: C) -> Self
pub fn new(search_space: Vec<SearchRange>, constructor: C) -> Self
Create Solver for search space and Specimen constructor closure.
The closure takes a Vec<f64> as argument, which contains the
coefficients/parameters, and it returns an S: Specimen.
See module level documentation for a code example.
For asynchronous constructors, method Solver::new_async can be used.
source§impl<S, C, F> Solver<S, C>where
C: Fn(Vec<f64>) -> F + Sync,
F: Future<Output = S> + Send,
impl<S, C, F> Solver<S, C>where C: Fn(Vec<f64>) -> F + Sync, F: Future<Output = S> + Send,
sourcepub fn new_async(search_space: Vec<SearchRange>, constructor: C) -> Self
pub fn new_async(search_space: Vec<SearchRange>, constructor: C) -> Self
Same as Solver::new, but takes an asynchronous constructor.
Note that when using this method, methods extend_specimens_async
and replace_worst_specimens_async must also be used instead of
their synchronous equivalents.
source§impl<S, C> Solver<S, C>where
S: Specimen + Send,
impl<S, C> Solver<S, C>where S: Specimen + Send,
sourcepub fn extend_specimens<I: IntoIterator<Item = S>>(&mut self, iter: I)
pub fn extend_specimens<I: IntoIterator<Item = S>>(&mut self, iter: I)
Add specimens to population.
sourcepub fn replace_worst_specimens<I: IntoIterator<Item = S>>(&mut self, iter: I)
pub fn replace_worst_specimens<I: IntoIterator<Item = S>>(&mut self, iter: I)
Replace worst specimens in population.
sourcepub async fn extend_specimens_async<F, I>(&mut self, iter: I)where
F: Future<Output = S> + Send,
I: IntoIterator<Item = F>,
pub async fn extend_specimens_async<F, I>(&mut self, iter: I)where F: Future<Output = S> + Send, I: IntoIterator<Item = F>,
Add specimens to population asynchronously.
sourcepub async fn replace_worst_specimens_async<F, I>(&mut self, iter: I)where
F: Future<Output = S> + Send,
I: IntoIterator<Item = F>,
pub async fn replace_worst_specimens_async<F, I>(&mut self, iter: I)where F: Future<Output = S> + Send, I: IntoIterator<Item = F>,
Replace worst specimens in population asynchronously.
sourcepub fn truncate_specimens(&mut self, count: usize)
pub fn truncate_specimens(&mut self, count: usize)
Truncate population of specimens to given count
(drops worst fitting specimens).
sourcepub fn converged(&mut self) -> bool
pub fn converged(&mut self) -> bool
Return true if specimens have converged.
Note that this method only returns true if the cost of all specimens is exactly equal. Additional, more sensitive termination conditions may be required in practice in order to avoid endless optimization.
sourcepub fn specimens(&mut self) -> &[S]
pub fn specimens(&mut self) -> &[S]
Sorted population of Specimens as shared slice (best first).
sourcepub fn specimens_mut(&mut self) -> &mut Vec<S>
pub fn specimens_mut(&mut self) -> &mut Vec<S>
sourcepub fn into_specimens(self) -> Vec<S>
pub fn into_specimens(self) -> Vec<S>
sourcepub fn into_specimen(self) -> S
pub fn into_specimen(self) -> S
source§impl<S, C, T> Solver<S, C>where
S: Specimen + Send + Sync,
C: Fn(Vec<f64>) -> T + Sync,
T: Send,
impl<S, C, T> Solver<S, C>where S: Specimen + Send + Sync, C: Fn(Vec<f64>) -> T + Sync, T: Send,
sourcepub fn random_specimens(&self, count: usize) -> Vec<T>
pub fn random_specimens(&self, count: usize) -> Vec<T>
Create random specimens
If Solver was created with Solver::new_async, then Futures of
specimens are returned instead.
sourcepub fn recombined_specimens(
&mut self,
children_count: usize,
local_factor: f64
) -> Vec<T>
pub fn recombined_specimens( &mut self, children_count: usize, local_factor: f64 ) -> Vec<T>
Create recombined specimens.
If Solver was created with Solver::new_async, then Futures of
specimens are returned instead.
Setting the local_factor to a value greater than 0.0 (but smaller
than 1.0) selects a particular specimen with a correspondingly
proportional chance to be modified. This allows performing more
localized searches. A reasonable value seems to be
0.01 / self.dim() as f64.