pub struct ActiveBayesianQuadrature { /* private fields */ }Expand description
Sequential active Bayesian quadrature over a finite candidate set.
Implementations§
Source§impl ActiveBayesianQuadrature
impl ActiveBayesianQuadrature
Sourcepub const fn new(quadrature: BayesianQuadrature) -> Self
pub const fn new(quadrature: BayesianQuadrature) -> Self
Construct active Bayesian quadrature from one consistent kernel/measure setup.
Examples found in repository?
examples/active_quadrature.rs (line 19)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let kernel = RbfKernel::new(1.0, 1.0)?;
17 let measure = GaussianMeasure::new(0.0, 1.0)?;
18 let quadrature = BayesianQuadrature::new(kernel, measure, 1.0e-10);
19 let active = ActiveBayesianQuadrature::new(quadrature);
20
21 // Start from three evaluations; allow up to six more from a fixed candidate grid,
22 // stopping early once the posterior variance of the integral drops below 1e-6.
23 let initial_nodes = [-1.0, 0.0, 1.0];
24 let initial_values: Vec<f64> = initial_nodes.iter().copied().map(integrand).collect();
25 let candidates: Vec<f64> = (0..=23).map(|i| -2.875 + 0.25 * f64::from(i)).collect();
26
27 let initial = quadrature.posterior(&initial_nodes, &initial_values)?;
28 println!("initial posterior variance = {:.3e}", initial.variance());
29
30 let result = active.run(
31 &initial_nodes,
32 &initial_values,
33 &candidates,
34 6,
35 1.0e-6,
36 integrand,
37 )?;
38
39 for step in result.steps() {
40 println!(
41 "x = {:+.3} predicted reduction = {:.3e} posterior variance = {:.3e}",
42 step.point(),
43 step.predicted_variance_reduction(),
44 step.posterior_variance(),
45 );
46 }
47
48 let exact = (1.0_f64 / 3.0).sqrt() * (-0.25_f64 / 3.0).exp();
49 let posterior = result.posterior();
50 println!("stopped because: {:?}", result.termination());
51 println!(
52 "E[I | y] = {:.6} ± {:.3e} (exact {exact:.6})",
53 posterior.mean(),
54 posterior.standard_deviation(),
55 );
56 Ok(())
57}Sourcepub const fn quadrature(&self) -> BayesianQuadrature
pub const fn quadrature(&self) -> BayesianQuadrature
Return the underlying Bayesian-quadrature configuration.
Sourcepub fn run<F>(
&self,
initial_nodes: &[f64],
initial_values: &[f64],
candidates: &[f64],
max_new_evaluations: usize,
variance_tolerance: f64,
function: F,
) -> Result<ActiveDesignResult, ActiveDesignError>
pub fn run<F>( &self, initial_nodes: &[f64], initial_values: &[f64], candidates: &[f64], max_new_evaluations: usize, variance_tolerance: f64, function: F, ) -> Result<ActiveDesignResult, ActiveDesignError>
Run sequential active selection and function evaluation.
The loop stops when the posterior integral variance is no greater than
variance_tolerance, when max_new_evaluations points have been added,
or when the finite candidate set is exhausted.
§Errors
Returns ActiveDesignError for invalid stopping tolerance, non-finite
candidates or function evaluations, candidate-selection failures, or
posterior-construction failures.
Examples found in repository?
examples/active_quadrature.rs (lines 30-37)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 let kernel = RbfKernel::new(1.0, 1.0)?;
17 let measure = GaussianMeasure::new(0.0, 1.0)?;
18 let quadrature = BayesianQuadrature::new(kernel, measure, 1.0e-10);
19 let active = ActiveBayesianQuadrature::new(quadrature);
20
21 // Start from three evaluations; allow up to six more from a fixed candidate grid,
22 // stopping early once the posterior variance of the integral drops below 1e-6.
23 let initial_nodes = [-1.0, 0.0, 1.0];
24 let initial_values: Vec<f64> = initial_nodes.iter().copied().map(integrand).collect();
25 let candidates: Vec<f64> = (0..=23).map(|i| -2.875 + 0.25 * f64::from(i)).collect();
26
27 let initial = quadrature.posterior(&initial_nodes, &initial_values)?;
28 println!("initial posterior variance = {:.3e}", initial.variance());
29
30 let result = active.run(
31 &initial_nodes,
32 &initial_values,
33 &candidates,
34 6,
35 1.0e-6,
36 integrand,
37 )?;
38
39 for step in result.steps() {
40 println!(
41 "x = {:+.3} predicted reduction = {:.3e} posterior variance = {:.3e}",
42 step.point(),
43 step.predicted_variance_reduction(),
44 step.posterior_variance(),
45 );
46 }
47
48 let exact = (1.0_f64 / 3.0).sqrt() * (-0.25_f64 / 3.0).exp();
49 let posterior = result.posterior();
50 println!("stopped because: {:?}", result.termination());
51 println!(
52 "E[I | y] = {:.6} ± {:.3e} (exact {exact:.6})",
53 posterior.mean(),
54 posterior.standard_deviation(),
55 );
56 Ok(())
57}Trait Implementations§
Source§impl Clone for ActiveBayesianQuadrature
impl Clone for ActiveBayesianQuadrature
Source§fn clone(&self) -> ActiveBayesianQuadrature
fn clone(&self) -> ActiveBayesianQuadrature
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ActiveBayesianQuadrature
Source§impl Debug for ActiveBayesianQuadrature
impl Debug for ActiveBayesianQuadrature
Source§impl PartialEq for ActiveBayesianQuadrature
impl PartialEq for ActiveBayesianQuadrature
impl StructuralPartialEq for ActiveBayesianQuadrature
Auto Trait Implementations§
impl Freeze for ActiveBayesianQuadrature
impl RefUnwindSafe for ActiveBayesianQuadrature
impl Send for ActiveBayesianQuadrature
impl Sync for ActiveBayesianQuadrature
impl Unpin for ActiveBayesianQuadrature
impl UnsafeUnpin for ActiveBayesianQuadrature
impl UnwindSafe for ActiveBayesianQuadrature
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Scalar for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.