Expand description
§hyperopt
Tree-of-Parzen-estimators hyperparameter optimization for Rust
§Examples
§Continuous
use std::f64::consts::{FRAC_PI_2, PI};
use approx::assert_abs_diff_eq;
use fastrand::Rng;
use ordered_float::NotNan;
use hyperopt::Optimizer;
use hyperopt::kde::Component;
use hyperopt::kernel::continuous::{Epanechnikov, Uniform};
fn main() {
let min = NotNan::new(FRAC_PI_2).unwrap();
let max = NotNan::new(PI + FRAC_PI_2).unwrap();
let mut optimizer = Optimizer::new(
min, max, // parameter search range
Component::<Uniform, NotNan<f64>>::new(min, max), // our initial guess is just as bad
Epanechnikov, // Epanechnikov kernel for the rescue
);
// Run 100 trials for the cosine function and try to find the point `(π, -1)`:
let mut rng = Rng::new();
for _ in 0..100 {
let x = optimizer.new_trial::<NotNan<f64>>(&mut rng);
optimizer.feed_back(x, NotNan::new(x.cos()).unwrap());
}
let best_trial = optimizer.best_trial().unwrap();
assert_abs_diff_eq!(best_trial.parameter.into_inner(), PI, epsilon = 0.25);
assert_abs_diff_eq!(best_trial.metric.into_inner(), -1.0, epsilon = 0.05);
}
§Discrete
Re-exports§
Modules§
- Additional constants that are missing in the standard library.
Structs§
- ✨ Hyperparameter optimizer.