Struct hyperopt::Optimizer

source ·
pub struct Optimizer<KInit, K, P, M> { /* private fields */ }
Expand description

✨ Hyperparameter optimizer.

§Generic parameters

  • [KInit]: kernel type of the initial (prior) estimator component
  • [K]: kernel type of the trials, it may (and will likely) be different from the prior component
  • [P]: type of parameter that is optimized
  • [M]: value of the target function, the less – the better

Implementations§

source§

impl<KFirst, K, P, M> Optimizer<KFirst, K, P, M>

source

pub const fn new( min: P, max: P, init_component: Component<KFirst, P>, kernel: K ) -> Self

Construct the new optimizer.

Here begins your adventure!

§Parameters
  • min and max: parameter range, bounds are included
  • init_component: 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.


  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<D>(&self, rng: &mut Rng) -> P
where KFirst: Copy + Density<P, D> + Sample<P>, K: Copy + Density<P, D> + Sample<P>, P: Add<Output = P> + Copy + Debug + Div<Output = P> + Mul<Output = P> + Ord + Sub<Output = P> + UnsafeInto<D>, D: Add<Output = D> + Copy + Debug + Div<Output = D> + Mul<Output = D> + Ord + UnsafeFromPrimitive<usize> + Zero,

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
  • [D]: kernel 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, K: Debug, P: Debug, M: Debug> Debug for Optimizer<KInit, K, P, M>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<KInit, K, P, M> UnwindSafe for Optimizer<KInit, K, 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.