Struct hyperopt::Optimizer

source ·
pub struct Optimizer<KInit, P, M> { /* 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

Implementations§

source§

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

source

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

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 const fn cutoff(self, cutoff: f64) -> Self

Set the ratio of «good» trials.

source

pub const fn n_candidates(self, n_candidates: 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 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: Additive + Copy + Ord,

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 KInit: Freeze, P: Freeze,

§

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

§

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

§

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

§

impl<KInit, P, M> Unpin for Optimizer<KInit, P, M>
where KInit: Unpin, P: 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>,

§

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

§

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.