Skip to main content

TpeSamplerBuilder

Struct TpeSamplerBuilder 

Source
pub struct TpeSamplerBuilder { /* private fields */ }
Expand description

Builder for configuring a TpeSampler.

This builder allows fluent configuration of TPE hyperparameters.

§Examples

use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .gamma(0.15)
    .n_startup_trials(20)
    .n_ei_candidates(32)
    .seed(42)
    .build();

Implementations§

Source§

impl TpeSamplerBuilder

Source

pub fn new() -> Self

Creates a new builder with default settings.

Default settings:

  • gamma: 0.25 (top 25% of trials are considered “good”)
  • n_startup_trials: 10 (random sampling for first 10 trials)
  • n_ei_candidates: 24 (evaluate 24 candidates per sample)
  • kde_bandwidth: None (uses Scott’s rule for automatic bandwidth)
  • seed: None (use OS-provided entropy)
Source

pub fn gamma(self, gamma: f64) -> Self

Sets the gamma quantile for splitting trials into good/bad groups.

A gamma of 0.25 means the top 25% of trials (by objective value) are considered “good” and used to build the l(x) distribution.

§Arguments
  • gamma - Quantile value, must be in (0.0, 1.0).
§Panics

Panics if gamma is not in (0.0, 1.0).

§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .gamma(0.10)  // Use top 10% as "good" trials
    .build();
Source

pub fn n_startup_trials(self, n: usize) -> Self

Sets the number of startup trials before TPE sampling begins.

During the startup phase, the sampler uses uniform random sampling to gather initial data. Once n_startup_trials have completed, TPE-based sampling begins.

§Arguments
  • n - Number of random trials before TPE kicks in.
§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .n_startup_trials(20)  // Random sample first 20 trials
    .build();
Source

pub fn n_ei_candidates(self, n: usize) -> Self

Sets the number of EI (Expected Improvement) candidates to evaluate.

When sampling a new point, TPE generates this many candidates from the l(x) distribution and selects the one with the highest l(x)/g(x) ratio.

§Arguments
  • n - Number of candidates to evaluate per sample.
§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .n_ei_candidates(48)  // Evaluate more candidates
    .build();
Source

pub fn kde_bandwidth(self, bandwidth: f64) -> Self

Sets a fixed bandwidth for the kernel density estimator.

By default, TPE uses Scott’s rule to automatically select the bandwidth based on the sample data. Use this method to override with a fixed value.

Smaller bandwidths give more localized, peaky distributions. Larger bandwidths give smoother, more spread-out distributions.

§Arguments
  • bandwidth - The fixed bandwidth (standard deviation) for Gaussian kernels.
§Panics

Panics if bandwidth is not positive.

§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .kde_bandwidth(0.5)  // Fixed bandwidth of 0.5
    .build();
Source

pub fn seed(self, seed: u64) -> Self

Sets a seed for reproducible sampling.

§Arguments
  • seed - Seed value for the random number generator.
§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .seed(42)  // Reproducible results
    .build();
Source

pub fn build(self) -> TpeSampler

Builds the configured TpeSampler.

§Examples
use optimizer::TpeSamplerBuilder;

let sampler = TpeSamplerBuilder::new()
    .gamma(0.15)
    .n_startup_trials(20)
    .n_ei_candidates(32)
    .seed(42)
    .build();

Trait Implementations§

Source§

impl Clone for TpeSamplerBuilder

Source§

fn clone(&self) -> TpeSamplerBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TpeSamplerBuilder

Source§

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

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

impl Default for TpeSamplerBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V