pub struct BayesianOptimization { /* private fields */ }Expand description
Bayesian Optimization for hyperparameter tuning.
Uses Gaussian Processes to model the objective function and acquisition functions to intelligently select the next hyperparameters to evaluate.
§Algorithm
- Initialize with random samples
- Fit Gaussian Process to observed data
- Optimize acquisition function to find next point
- Evaluate objective at new point
- Repeat steps 2-4 until budget exhausted
§Example
use tensorlogic_train::*;
use std::collections::HashMap;
let mut param_space = HashMap::new();
param_space.insert(
"lr".to_string(),
HyperparamSpace::log_uniform(1e-4, 1e-1).unwrap(),
);
let mut bayes_opt = BayesianOptimization::new(
param_space,
10, // n_iterations
5, // n_initial_points
42, // seed
);
// In practice, you would evaluate your model here
// bayes_opt.add_result(result);Implementations§
Source§impl BayesianOptimization
impl BayesianOptimization
Sourcepub fn new(
param_space: HashMap<String, HyperparamSpace>,
n_iterations: usize,
n_initial_points: usize,
seed: u64,
) -> Self
pub fn new( param_space: HashMap<String, HyperparamSpace>, n_iterations: usize, n_initial_points: usize, seed: u64, ) -> Self
Create a new Bayesian Optimization instance.
§Arguments
param_space- Hyperparameter space definitionn_iterations- Number of optimization iterationsn_initial_points- Number of random initialization pointsseed- Random seed for reproducibility
Sourcepub fn with_acquisition(self, acquisition_fn: AcquisitionFunction) -> Self
pub fn with_acquisition(self, acquisition_fn: AcquisitionFunction) -> Self
Set acquisition function.
Sourcepub fn with_kernel(self, kernel: GpKernel) -> Self
pub fn with_kernel(self, kernel: GpKernel) -> Self
Set kernel.
Sourcepub fn with_noise(self, noise_variance: f64) -> Self
pub fn with_noise(self, noise_variance: f64) -> Self
Set noise variance.
Sourcepub fn suggest(&mut self) -> TrainResult<HyperparamConfig>
pub fn suggest(&mut self) -> TrainResult<HyperparamConfig>
Suggest next hyperparameter configuration to evaluate.
Sourcepub fn add_result(&mut self, result: HyperparamResult)
pub fn add_result(&mut self, result: HyperparamResult)
Add a result from evaluating a configuration.
Sourcepub fn best_result(&self) -> Option<&HyperparamResult>
pub fn best_result(&self) -> Option<&HyperparamResult>
Get the best result found so far.
Sourcepub fn sorted_results(&self) -> Vec<&HyperparamResult>
pub fn sorted_results(&self) -> Vec<&HyperparamResult>
Get all results sorted by score (descending).
Sourcepub fn results(&self) -> &[HyperparamResult]
pub fn results(&self) -> &[HyperparamResult]
Get all results.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if optimization is complete.
Sourcepub fn current_iteration(&self) -> usize
pub fn current_iteration(&self) -> usize
Get current iteration number.
Sourcepub fn total_budget(&self) -> usize
pub fn total_budget(&self) -> usize
Get total budget (initial + iterations).
Auto Trait Implementations§
impl Freeze for BayesianOptimization
impl RefUnwindSafe for BayesianOptimization
impl Send for BayesianOptimization
impl Sync for BayesianOptimization
impl Unpin for BayesianOptimization
impl UnsafeUnpin for BayesianOptimization
impl UnwindSafe for BayesianOptimization
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more