Skip to main content

Crate parzen

Crate parzen 

Source
Expand description

High-performance Tree-structured Parzen Estimator optimization.

use parzen::{
    CategoricalDistribution, Direction, Distribution, SearchSpace, Study,
    TpeSampler, TpeSamplerConfig,
};

let mut space = SearchSpace::new();
space.add("x", Distribution::Categorical(CategoricalDistribution::new(5)?))?;
let sampler = TpeSampler::new(TpeSamplerConfig::performance(42).startup_trials(5))?;
let mut study = Study::new(Direction::Maximize, sampler, space)?;

for _ in 0..20 {
    let x = study.suggest_categorical("x")?;
    study.complete_trial(if x == 2 { 1.0 } else { 0.1 })?;
}
assert!(study.best_value().is_some_and(|value| value > 0.5));

Explicit parameter groups use one trial-aligned mixture component for the entire vector. Their joint likelihood is logsumexp(log(weight[k]) + sum_d log(kernel[d][k](x[d]))), preserving correlations that independent marginal models discard. Integer and stepped distributions integrate each Gaussian kernel over the selected grid cell instead of treating a discrete value as a continuous point.

HistoryPolicy::Bounded keeps a fixed-size exact best set, recent bad observations, and a deterministic reservoir, so estimator state and incremental update work do not grow with completed-trial count. Raw trial records remain complete. HistoryPolicy::Full retains exact full-history ranking and therefore has linear storage and model-construction costs.

Structs§

CategoricalDistribution
A categorical distribution represented by choice indices.
FloatDistribution
A bounded floating-point distribution.
GroupId
Stable explicit multivariate-group identifier.
IntDistribution
A bounded integer distribution.
ParamId
Stable parameter identifier within one search space.
ParameterRef
Read-only information about a registered parameter.
Params
Iterator over one trial’s parameter names and values.
SearchSpace
A validated collection of parameter distributions, conditions, and groups.
Study
A sequential Bayesian optimization study.
TpeSampler
Seeded Tree-structured Parzen Estimator sampler.
TpeSamplerConfig
Validated sampler configuration.
TrialId
Stable identifier assigned to a completed trial.
TrialInput
Owned input for injecting a completed trial.
TrialRecord
Owned, serializable representation of a completed trial.
TrialRef
Borrowed, allocation-free view of a completed trial.
Trials
Exact-size, double-ended iterator over completed trials.

Enums§

Condition
A condition controlling whether a parameter is active.
Direction
Optimization direction.
Distribution
A categorical, floating-point, or integer search distribution.
FloatScale
Scale used by a floating-point distribution.
GammaStrategy
Strategy mapping applicable observation count to good-trial count.
HistoryPolicy
Amount of estimator history retained.
IntScale
Scale used by an integer distribution.
ModelStrategy
Independent or explicit-group multivariate modeling.
ParamValue
A typed parameter value.
ParzenError
An invalid configuration, search space, trial, or study operation.
WeightStrategy
Observation weighting strategy.