pub struct TpeSampler { /* private fields */ }Expand description
Tree-structured Parzen Estimator sampler.
This wraps the tpe crate rather than
reimplementing TPE from scratch — a real integration point, not a stubbed
gap. The work this type does is translating between hyperopt-core’s
Distribution/Trial history and tpe’s per-parameter TpeOptimizer
(one optimizer handles exactly one hyperparameter), including:
- mapping each
Distributionvariant onto atperange + estimator (Parzen for numeric, histogram for categorical), - encoding values into
tpe’s coordinate space (log forLogUniform, index forCategorical,[low, high+1)forIntUniform) and decoding the sampled result back, - honouring the study
Directionby negating objective values underMaximize, sincetpealways minimizes.
The sampler is effectively stateless over trial history: each
suggest rebuilds a TpeOptimizer from the study snapshot and replays the
relevant observations. This makes it correct under both parallel execution
(it simply works from whatever snapshot it’s given) and study reload from
storage, at an O(n) per-suggestion cost that is negligible next to a real
objective evaluation.
§Limitations (documented, not silent)
- The first
n_startup_trialscompleted trials are sampled at random to seed the estimators — matching Optuna’s warmup and avoiding a biased model from too few points. - Every
hyperopt-coreDistributionvariant maps ontotpe. There is no varianttpecannot represent here; should a future distribution not map cleanly, this sampler falls back to a random draw for it rather than producing an out-of-range value.
Implementations§
Source§impl TpeSampler
impl TpeSampler
Sourcepub fn new() -> TpeSampler
pub fn new() -> TpeSampler
A TPE sampler with default warmup (n_startup_trials = 10), seeded from
OS entropy.
Sourcepub fn seeded(seed: u64) -> TpeSampler
pub fn seeded(seed: u64) -> TpeSampler
A TPE sampler with a fixed seed — reproducible for tests/benchmarks.
Sourcepub fn n_startup_trials(self, n: usize) -> TpeSampler
pub fn n_startup_trials(self, n: usize) -> TpeSampler
Number of initial trials to sample randomly before building TPE models.