pub struct Variable { /* private fields */ }Expand description
A number the optimizer may change: its name, where it starts, the size of its first steps,
the range it must stay in, and whether it takes only whole numbers. It serializes as its
fields (an unbounded side as null; integer only when true, and read as false when
absent), and reads back through Variable::new, Variable::within and Variable::integer’s checks.
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new(
name: impl Into<String>,
start: f64,
step: f64,
) -> Result<Self, AnalysisError>
pub fn new( name: impl Into<String>, start: f64, step: f64, ) -> Result<Self, AnalysisError>
A variable named name, starting at start, with no bounds. step is the size of the
optimizer’s first steps in it: about a quarter to a third of the range its best value is
expected in, in the variable’s own units.
§Errors
AnalysisError::Domain for a start that isn’t finite, or a step that isn’t finite
and positive.
Sourcepub fn within(self, low: f64, high: f64) -> Result<Self, AnalysisError>
pub fn within(self, low: f64, high: f64) -> Result<Self, AnalysisError>
The same variable, held to [low, high]. Either bound may be infinite, for none.
§Errors
AnalysisError::Domain for a NaN bound, a high not above low, a start outside
the range, or for an integer variable bounds that aren’t whole numbers within ±2⁵².
Sourcepub fn integer(self) -> Result<Self, AnalysisError>
pub fn integer(self) -> Result<Self, AnalysisError>
The same variable, taking only the whole numbers from its low bound to its high one: a
count, or the place of a choice in a list (a motor, a catalog part). The optimizer still
draws it as a real number, and the model is given the whole number nearest the draw,
clamped to the bounds (Variable::encode); cmaes keeps every value within reach by
the margin of CMA-ES with margin. Its step is the size of the first steps, in whole
numbers: 1 is a good start for a handful of choices. Its start may lie between two whole
numbers, as the draws are centered on it.
§Errors
AnalysisError::Domain for bounds that aren’t whole numbers within ±2⁵²: set them
first with Variable::within, which checks them again if called after.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Whether it takes only whole numbers (Variable::integer).
Sourcepub fn encode(&self, x: f64) -> f64
pub fn encode(&self, x: f64) -> f64
The value the model is given for a draw x: x itself, or for an integer variable the
whole number nearest x, a draw halfway between two going to the lower, clamped to the
bounds. These are the encoding of R. Hamano et al., “CMA-ES with Margin”, GECCO 2022
(arXiv:2205.13482, §4.1, p. 5), with thresholds halfway between neighbouring values. NaN
stays NaN (a run stops before it would draw one).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Variable
impl<'de> Deserialize<'de> for Variable
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 Variable
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnsafeUnpin for Variable
impl UnwindSafe for Variable
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