Struct argmin::solver::neldermead::NelderMead
source · [−]pub struct NelderMead<P, F> { /* private fields */ }
Expand description
Nelder-Mead method
The Nelder-Mead method a heuristic search method for nonlinear optimization problems which does not require derivatives.
The method is based on simplices which consist of n+1 vertices for an optimization problem with n dimensions. The function to be optimized is evaluated at all vertices. Based on these cost function values the behaviour of the cost function is extrapolated in order to find the next point to be evaluated.
The following actions are possible:
- Reflection (Parameter
alpha
, defaults to1
, configurable viawith_alpha
) - Expansion (Parameter
gamma
, defaults to2
, configurable viawith_gamma
) - Contraction inside or outside (Parameter
rho
, defaults to0.5
, configurable viawith_rho
) - Shrink (Parameter
sigma
, defaults to0.5
, configurable viawith_sigma
)
Requirements on the optimization problem
The optimization problem is required to implement CostFunction
.
References
https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method
http://www.scholarpedia.org/article/Nelder-Mead_algorithm#Simplex_transformation_algorithm
Implementations
sourceimpl<P, F> NelderMead<P, F> where
P: Clone + ArgminAdd<P, P> + ArgminSub<P, P> + ArgminMul<F, P>,
F: ArgminFloat,
impl<P, F> NelderMead<P, F> where
P: Clone + ArgminAdd<P, P> + ArgminSub<P, P> + ArgminMul<F, P>,
F: ArgminFloat,
sourcepub fn new(params: Vec<P>) -> Self
pub fn new(params: Vec<P>) -> Self
Construct a new instance of NelderMead
Takes a vector of parameter vectors. The number of parameter vectors must be n + 1
where
n
is the number of optimization parameters.
Example
let nm: NelderMead<Vec<f64>, f64> = NelderMead::new(vec_of_parameters);
sourcepub fn with_sd_tolerance(self, tol: F) -> Result<Self, Error>
pub fn with_sd_tolerance(self, tol: F) -> Result<Self, Error>
Set sample standard deviation tolerance
Must be non-negative and defaults to EPSILON
.
Example
let nm: NelderMead<Vec<f64>, f64> =
NelderMead::new(vec_of_parameters).with_sd_tolerance(1e-6)?;
sourcepub fn with_alpha(self, alpha: F) -> Result<Self, Error>
pub fn with_alpha(self, alpha: F) -> Result<Self, Error>
Set alpha parameter for reflection
Must be larger than 0 and defaults to 1.
Example
let nm: NelderMead<Vec<f64>, f64> =
NelderMead::new(vec_of_parameters).with_alpha(0.9)?;
sourcepub fn with_gamma(self, gamma: F) -> Result<Self, Error>
pub fn with_gamma(self, gamma: F) -> Result<Self, Error>
Set gamma for expansion
Must be larger than 1 and defaults to 2.
Example
let nm: NelderMead<Vec<f64>, f64> =
NelderMead::new(vec_of_parameters).with_gamma(1.9)?;
sourcepub fn with_rho(self, rho: F) -> Result<Self, Error>
pub fn with_rho(self, rho: F) -> Result<Self, Error>
Set rho for contraction
Must be in (0, 0.5] and defaults to 0.5.
Example
let nm: NelderMead<Vec<f64>, f64> =
NelderMead::new(vec_of_parameters).with_rho(0.4)?;
sourcepub fn with_sigma(self, sigma: F) -> Result<Self, Error>
pub fn with_sigma(self, sigma: F) -> Result<Self, Error>
Set sigma for shrinking
Must be in (0, 1] and defaults to 0.5.
Example
let nm: NelderMead<Vec<f64>, f64> =
NelderMead::new(vec_of_parameters).with_sigma(0.4)?;
Trait Implementations
sourceimpl<P: Clone, F: Clone> Clone for NelderMead<P, F>
impl<P: Clone, F: Clone> Clone for NelderMead<P, F>
sourcefn clone(&self) -> NelderMead<P, F>
fn clone(&self) -> NelderMead<P, F>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'de, P, F> Deserialize<'de> for NelderMead<P, F> where
P: Deserialize<'de>,
F: Deserialize<'de>,
impl<'de, P, F> Deserialize<'de> for NelderMead<P, F> where
P: Deserialize<'de>,
F: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<P, F> Serialize for NelderMead<P, F> where
P: Serialize,
F: Serialize,
impl<P, F> Serialize for NelderMead<P, F> where
P: Serialize,
F: Serialize,
sourceimpl<O, P, F> Solver<O, IterState<P, (), (), (), F>> for NelderMead<P, F> where
O: CostFunction<Param = P, Output = F>,
P: Clone + SerializeAlias + ArgminSub<P, P> + ArgminAdd<P, P> + ArgminMul<F, P>,
F: ArgminFloat + Sum<F>,
impl<O, P, F> Solver<O, IterState<P, (), (), (), F>> for NelderMead<P, F> where
O: CostFunction<Param = P, Output = F>,
P: Clone + SerializeAlias + ArgminSub<P, P> + ArgminAdd<P, P> + ArgminMul<F, P>,
F: ArgminFloat + Sum<F>,
sourcefn init(
&mut self,
problem: &mut Problem<O>,
state: IterState<P, (), (), (), F>
) -> Result<(IterState<P, (), (), (), F>, Option<KV>), Error>
fn init(
&mut self,
problem: &mut Problem<O>,
state: IterState<P, (), (), (), F>
) -> Result<(IterState<P, (), (), (), F>, Option<KV>), Error>
Initializes the algorithm. Read more
sourcefn next_iter(
&mut self,
problem: &mut Problem<O>,
state: IterState<P, (), (), (), F>
) -> Result<(IterState<P, (), (), (), F>, Option<KV>), Error>
fn next_iter(
&mut self,
problem: &mut Problem<O>,
state: IterState<P, (), (), (), F>
) -> Result<(IterState<P, (), (), (), F>, Option<KV>), Error>
sourcefn terminate(
&mut self,
_state: &IterState<P, (), (), (), F>
) -> TerminationReason
fn terminate(
&mut self,
_state: &IterState<P, (), (), (), F>
) -> TerminationReason
Used to implement stopping criteria, in particular criteria which are not covered by
(terminate_internal
. Read more
sourcefn terminate_internal(&mut self, state: &I) -> TerminationReason
fn terminate_internal(&mut self, state: &I) -> TerminationReason
Checks whether basic termination reasons apply. Read more
Auto Trait Implementations
impl<P, F> RefUnwindSafe for NelderMead<P, F> where
F: RefUnwindSafe,
P: RefUnwindSafe,
impl<P, F> Send for NelderMead<P, F> where
F: Send,
P: Send,
impl<P, F> Sync for NelderMead<P, F> where
F: Sync,
P: Sync,
impl<P, F> Unpin for NelderMead<P, F> where
F: Unpin,
P: Unpin,
impl<P, F> UnwindSafe for NelderMead<P, F> where
F: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more