Optimizer

Struct Optimizer 

Source
pub struct Optimizer<KInit, P, M> {
    pub cutoff: f64,
    pub n_candidates: usize,
    pub bandwidth: P,
    /* private fields */
}
Expand description

✨ Hyperparameter optimizer.

§Generic parameters

  • [KInit]: kernel type of the initial (prior) estimator component
  • [P]: type of parameter that is optimized
  • [M]: value of the target function, the less – the better

Fields§

§cutoff: f64§n_candidates: usize§bandwidth: P

Implementations§

Source§

impl<KInit, P, M> Optimizer<KInit, P, M>

Source

pub fn new(range: RangeInclusive<P>, init_kernel: KInit, rng: Rng) -> Self
where P: One,

Construct the new optimizer.

Here begins your adventure!

§Parameters
  • range: parameter search range, Optimizer will clamp random samples to this range
  • init_kernel: your prior belief about which values of the searched parameter is more optimal
  • kernel: kernel for the trial components
Source

pub fn cutoff(self, cutoff: impl Into<f64>) -> Self

Set the ratio of «good» trials.

Source

pub fn n_candidates(self, n_candidates: impl Into<usize>) -> Self

Set the number of candidates to choose the next trial from the acquisition function1.

Sampling from the acquisition function is cheaper than evaluating the target cost function, so the more candidates – the more effective is the optimization step.

However, the acquisition function is an approximation of a potential gain, so the fewer candidates – the more precise is the optimization step.

The number of candidates is therefore a tradeoff.


  1. Acquisition function is basically a ratio between the «good» KDE and «bad» KDE at the same point. 

Source

pub fn bandwidth(self, bandwidth: impl Into<P>) -> Self

Set the bandwidth multiplier for the estimator kernels.

Standard deviation of the kernel is the distance from the point to its furthest neighbour, multiplied by this coefficient.

The default multiplier is [P::one]. Lower bandwidth approximates the density better, however, is also prone to over-fitting. Higher bandwidth avoid over-fitting better, but is also smoother and less precise.

Source

pub fn feed_back(&mut self, parameter: P, metric: M)
where P: Copy + Debug + Ord, M: Debug + Ord,

Provide the information about the trial, or in other words, «fit» the optimizer on the sample.

Normally, you’ll call your target function on parameters supplied by Optimizer::new_trial, and feed back the results. But you also can feed it with any arbitrary parameters.

§Parameters
  • parameter: the target function parameter
  • metric: the target function metric
Source

pub fn new_trial<K>(&mut self) -> P
where KInit: Copy + Density<Param = P> + Sample<Param = P>, KInit::Output: Copy + Debug + Ord + Multiplicative + FromPrimitive + Zero, K: Copy + Kernel<Param = P> + Sample<Param = P> + Density<Param = P, Output = <KInit as Density>::Output>, P: Copy + Ord + SelfSub + SelfMul,

Generate a parameter value for a new trial.

After evaluating the target function with this parameter, you’d better feed the metric back with Optimizer::feed_back.

§Type parameters
  • [K]: kernel type
  • [D]: kernel density type
§Panics

This method may panic if a random or calculated number cannot be converted to the parameter or density type.

Source

pub fn best_trial(&self) -> Option<&Trial<P, M>>
where P: Ord, M: Ord,

Get the best trial.

Trait Implementations§

Source§

impl<KInit: Debug, P: Debug, M: Debug> Debug for Optimizer<KInit, P, M>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<KInit, P, M> Freeze for Optimizer<KInit, P, M>
where P: Freeze, KInit: Freeze,

§

impl<KInit, P, M> RefUnwindSafe for Optimizer<KInit, P, M>

§

impl<KInit, P, M> Send for Optimizer<KInit, P, M>
where P: Send, KInit: Send, M: Send,

§

impl<KInit, P, M> Sync for Optimizer<KInit, P, M>
where P: Sync, KInit: Sync, M: Sync,

§

impl<KInit, P, M> Unpin for Optimizer<KInit, P, M>
where P: Unpin, KInit: Unpin,

§

impl<KInit, P, M> UnwindSafe for Optimizer<KInit, P, M>

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