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
impl TpeSamplerBuilder
Sourcepub fn new() -> Self
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)
Sourcepub fn gamma(self, gamma: f64) -> Self
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();Sourcepub fn n_startup_trials(self, n: usize) -> Self
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();Sourcepub fn n_ei_candidates(self, n: usize) -> Self
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();Sourcepub fn kde_bandwidth(self, bandwidth: f64) -> Self
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();Sourcepub fn build(self) -> TpeSampler
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
impl Clone for TpeSamplerBuilder
Source§fn clone(&self) -> TpeSamplerBuilder
fn clone(&self) -> TpeSamplerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more