pub struct BayesianOptimizer {
pub bounds: Vec<(f64, f64)>,
pub gp: GaussianProcess,
pub x_observed: Vec<Vec<f64>>,
pub y_observed: Vec<f64>,
pub best_y: f64,
pub best_x: Vec<f64>,
pub opts: BayesOpts,
}Expand description
Bayesian optimization over a bounded box using a GP surrogate.
The optimizer maintains a GP fitted to all observations so far, and at each step proposes the point that maximises the acquisition function.
Fields§
§bounds: Vec<(f64, f64)>Search space bounds: one (lo, hi) per dimension.
gp: GaussianProcessGP surrogate.
x_observed: Vec<Vec<f64>>All observed inputs.
y_observed: Vec<f64>All observed outputs.
best_y: f64Best output value observed so far.
best_x: Vec<f64>Input that yielded best_y.
opts: BayesOptsOptimizer configuration.
Implementations§
Source§impl BayesianOptimizer
impl BayesianOptimizer
Sourcepub fn new(
bounds: Vec<(f64, f64)>,
kernel: KernelType,
params: KernelParams,
opts: BayesOpts,
) -> Self
pub fn new( bounds: Vec<(f64, f64)>, kernel: KernelType, params: KernelParams, opts: BayesOpts, ) -> Self
Construct a new optimizer.
bounds— axis-aligned box, one(lo, hi)per input dimension.kernel— kernel type for the GP surrogate.params— kernel hyper-parameters.opts— algorithm options (number of iterations, acquisition, …).
Sourcepub fn update(&mut self, x: Vec<f64>, y: f64) -> Result<(), String>
pub fn update(&mut self, x: Vec<f64>, y: f64) -> Result<(), String>
Incorporate a new observation (x, y) into the optimizer state.
The GP surrogate is re-fitted after each call.
Sourcepub fn suggest_next(&self) -> Vec<f64>
pub fn suggest_next(&self) -> Vec<f64>
Suggest the next candidate point to evaluate.
Uses Latin-hypercube random candidates and picks the one with the highest acquisition value. Falls back to a random LHS point if the GP has not been fitted yet.
Sourcepub fn optimize<F>(&mut self, f: F) -> (Vec<f64>, f64)
pub fn optimize<F>(&mut self, f: F) -> (Vec<f64>, f64)
Run the full optimization loop, evaluating the black-box f.
First draws n_initial LHS points, then iterates for max_iter
steps. Returns the best (x, y) pair found.
Sourcepub fn n_observations(&self) -> usize
pub fn n_observations(&self) -> usize
Number of observations collected so far.
Trait Implementations§
Source§impl Clone for BayesianOptimizer
impl Clone for BayesianOptimizer
Source§fn clone(&self) -> BayesianOptimizer
fn clone(&self) -> BayesianOptimizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BayesianOptimizer
impl RefUnwindSafe for BayesianOptimizer
impl Send for BayesianOptimizer
impl Sync for BayesianOptimizer
impl Unpin for BayesianOptimizer
impl UnsafeUnpin for BayesianOptimizer
impl UnwindSafe for BayesianOptimizer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.