pub struct Cmaes { /* private fields */ }Expand description
The optimizer’s settings: the variables, the population, and when to stop. It serializes as
its fields, and reads back through the same checks as Cmaes::new and its with_ methods.
Implementations§
Source§impl Cmaes
impl Cmaes
Sourcepub fn new(variables: Vec<Variable>) -> Result<Self, AnalysisError>
pub fn new(variables: Vec<Variable>) -> Result<Self, AnalysisError>
The optimizer over variables, with the tutorial’s default population
λ = 4 + ⌊3 ln n⌋, at most 10,000 evaluations, no target, and tolerances of 10⁻¹² (in
the variables, as a fraction of each one’s step; and in the output, in its own units).
§Errors
AnalysisError::TooFew for no variables, AnalysisError::Count for more than
MAX_VARIABLES, and AnalysisError::DuplicateVariable for two
with one name.
Sourcepub fn with_population(self, lambda: usize) -> Result<Self, AnalysisError>
pub fn with_population(self, lambda: usize) -> Result<Self, AnalysisError>
The same, with λ candidates a generation. A larger population searches more widely,
which helps on outputs with many local minima, at more evaluations a generation.
§Errors
AnalysisError::TooFew for fewer than 2, AnalysisError::Count for more than
MAX_POPULATION.
Sourcepub fn with_max_evaluations(self, max: usize) -> Result<Self, AnalysisError>
pub fn with_max_evaluations(self, max: usize) -> Result<Self, AnalysisError>
The same, stopping once max evaluations have been made (it finishes the generation, so
it may make up to λ − 1 more).
§Errors
AnalysisError::TooFew for none.
Sourcepub fn with_target(self, target: f64) -> Result<Self, AnalysisError>
pub fn with_target(self, target: f64) -> Result<Self, AnalysisError>
The same, stopping once a value at or below target is found.
§Errors
AnalysisError::Domain for a target that isn’t finite: an infinite one would be met by
a generation whose every candidate failed.
Sourcepub fn with_tolerance_x(self, tolerance: f64) -> Result<Self, AnalysisError>
pub fn with_tolerance_x(self, tolerance: f64) -> Result<Self, AnalysisError>
The same, ending a run once the distribution’s spread, and its evolution path, are below
tolerance times each variable’s step in every variable (Stop::TolX). Zero turns the
test off.
§Errors
AnalysisError::Domain for a tolerance that is negative or not finite.
Sourcepub fn with_tolerance_value(self, tolerance: f64) -> Result<Self, AnalysisError>
pub fn with_tolerance_value(self, tolerance: f64) -> Result<Self, AnalysisError>
The same, ending a run once its recent values all lie within tolerance of each other, in
the output’s units (Stop::TolFun). Zero turns the test off.
§Errors
AnalysisError::Domain for a tolerance that is negative or not finite.
Sourcepub fn population(&self) -> usize
pub fn population(&self) -> usize
The population, λ.
Sourcepub fn start(&self, seed: u64) -> Result<Run, AnalysisError>
pub fn start(&self, seed: u64) -> Result<Run, AnalysisError>
Starts a run from seed, with its first generation drawn. Evaluate the candidates, give
their values to Run::tell, and repeat until it returns why it stopped.
§Errors
AnalysisError::OutOfBounds if a first candidate can’t be drawn inside the bounds, and
AnalysisError::Domain if one overflows (steps near f64::MAX).
Sourcepub fn minimize_constrained(
&self,
seed: u64,
model: impl FnMut(&[f64]) -> Evaluation,
) -> Result<Optimum, AnalysisError>
pub fn minimize_constrained( &self, seed: u64, model: impl FnMut(&[f64]) -> Evaluation, ) -> Result<Optimum, AnalysisError>
Minimizes model under constraints from seed, evaluating each candidate in turn: the
model gives each candidate’s Evaluation, and Run::tell_constrained ranks them.
If no candidate keeps every constraint, the optimum’s violation
is above zero: check it before using the point.
§Errors
Cmaes::start’s and Run::tell_constrained’s.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cmaes
impl<'de> Deserialize<'de> for Cmaes
Source§fn 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>,
impl StructuralPartialEq for Cmaes
Auto Trait Implementations§
impl Freeze for Cmaes
impl RefUnwindSafe for Cmaes
impl Send for Cmaes
impl Sync for Cmaes
impl Unpin for Cmaes
impl UnsafeUnpin for Cmaes
impl UnwindSafe for Cmaes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more