Skip to main content

Variable

Struct Variable 

Source
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

Source

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.

Source

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⁵².

Source

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.

Source

pub fn is_integer(&self) -> bool

Whether it takes only whole numbers (Variable::integer).

Source

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).

Source

pub fn name(&self) -> &str

Its name.

Source

pub fn start(&self) -> f64

Where it starts.

Source

pub fn step(&self) -> f64

The size of its first steps.

Source

pub fn low(&self) -> f64

Its low bound, −∞ for none.

Source

pub fn high(&self) -> f64

Its high bound, +∞ for none.

Source

pub fn contains(&self, x: f64) -> bool

Whether x is within its bounds.

Trait Implementations§

Source§

impl Clone for Variable

Source§

fn clone(&self) -> Variable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Variable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Variable

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Variable

Source§

fn eq(&self, other: &Variable) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Variable

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Variable

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.