Struct tpe::TpeOptimizer [−][src]
pub struct TpeOptimizer<T = DefaultEstimatorBuilder> { /* fields omitted */ }
Expand description
Optimizer using TPE.
This try to search out the parameter value which could minimize the evaluation result.
Note that an instance of TpeOptimizer can handle only one hyperparameter. So if you want to optimize multiple hyperparameters simultaneously, please create an optimizer for each hyperparameter.
Implementations
Makes a new TpeOptimizer
with the default settings.
If you want to customize the settings, please use TpeOptimizerBuilder
instead.
Returns the next value of the optimization target parameter to be evaluated.
Note that, before the first asking, it might be worth to give some evaluation
results of randomly sampled observations to TpeOptimizer
(via the tell
method)
to reduce bias due to too few samples.
Tells the evaluation result of a hyperparameter value to the optimizer.
Note that the param
should be NaN if the hyperparameter was not used in the evaluation
(this could be happen when the entire search space is conditional).
Retruns all told parameter and objective values.
Note that the order of items in the returned iterator doesn’t reflect the order TpeOptimizer::tell
called.
Examples
You can this method to store and load the state of a TpeOptimizer
.
let temp_file = tempfile::NamedTempFile::new()?;
let mut rng = rand::thread_rng();
fn objective(x: f64) -> f64 {
x.powi(2)
}
{
let mut optim =
tpe::TpeOptimizer::new(tpe::parzen_estimator(), tpe::range(-5.0, 5.0)?);
// Runs 100 trials.
for _ in 0..100 {
let x = optim.ask(&mut rng)?;
let v = objective(x);
optim.tell(x, v)?;
}
// Stores the trials.
let mut file = std::fs::OpenOptions::new()
.write(true)
.open(temp_file.path())?;
serde_json::to_writer(&mut file, &optim.trials().collect::<Vec<_>>())?;
}
{
let mut optim =
tpe::TpeOptimizer::new(tpe::parzen_estimator(), tpe::range(-5.0, 5.0)?);
// Loads the previous trials.
let mut file = std::fs::File::open(temp_file.path())?;
let trials: Vec<(f64, f64)> = serde_json::from_reader(&mut file)?;
for (x, v) in trials {
optim.tell(x, v)?;
}
// Runs additional 100 trials.
for _ in 0..100 {
let x = optim.ask(&mut rng)?;
let v = objective(x);
optim.tell(x, v)?;
}
assert_eq!(optim.trials().count(), 200);
}
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for TpeOptimizer<T> where
T: RefUnwindSafe,
impl<T> Send for TpeOptimizer<T> where
T: Send,
impl<T> Sync for TpeOptimizer<T> where
T: Sync,
impl<T> Unpin for TpeOptimizer<T> where
T: Unpin,
impl<T> UnwindSafe for TpeOptimizer<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.