BayesianQuadrature¶
- class probnum.quad.BayesianQuadrature(kernel, measure, policy, belief_update, stopping_criterion)¶
Bases:
object
A base class for Bayesian quadrature.
Bayesian quadrature solves integrals of the form
\[F = \int_\Omega f(x) d \mu(x).\]- Parameters
kernel (Kernel) – The kernel used for the GP model.
measure (IntegrationMeasure) – The integration measure.
policy (Policy) – The policy choosing nodes at which to evaluate the integrand.
belief_update (BQBeliefUpdate) – The inference method.
stopping_criterion (BQStoppingCriterion) – The criterion that determines convergence.
- Return type
None
Methods Summary
bq_iterator
([fun, nodes, fun_evals, ...])Generator that implements the iteration of the BQ method.
from_problem
(input_dim[, kernel, measure, ...])Alternative way to initialize
Bayesian_Quadrature
has_converged
(bq_state, info)Checks if the BQ method has converged.
integrate
([fun, nodes, fun_evals])Integrate the function
fun
.Methods Documentation
- bq_iterator(fun=None, nodes=None, fun_evals=None, integral_belief=None, bq_state=None, info=None)[source]¶
Generator that implements the iteration of the BQ method.
This function exposes the state of the BQ method one step at a time while running the loop.
- Parameters
fun (Optional[Callable]) – Function to be integrated. It needs to accept a shape=(n_eval, input_dim)
np.ndarray
and return a shape=(n_eval,)np.ndarray
.nodes (Optional[ndarray]) – shape=(n_eval, input_dim) – Optional nodes at which function evaluations are available as
fun_evals
from start.fun_evals (Optional[ndarray]) – shape=(n_eval,) – Optional function evaluations at
nodes
available from the start.integral_belief (Optional[Normal]) – Current belief about the integral.
bq_state (Optional[BQState]) – State of the Bayesian quadrature methods. Contains all necessary information about the problem and the computation.
info (Optional[BQIterInfo]) – The state of the iteration.
- Yields
new_integral_belief – Updated belief about the integral.
new_nodes – shape=(n_new_eval, input_dim) – The new location(s) at which
new_fun_evals
are available found during the iteration.new_fun_evals – shape=(n_new_eval,) – The function evaluations at the new locations
new_nodes
.new_bq_state – Updated state of the Bayesian quadrature methods.
new_info – Updated state of the iteration.
- Return type
- classmethod from_problem(input_dim, kernel=None, measure=None, domain=None, policy='bmc', max_evals=None, var_tol=None, rel_tol=None, batch_size=1, rng=None)[source]¶
Alternative way to initialize
Bayesian_Quadrature
- Parameters
input_dim (int) – Input dimension.
kernel (Optional[Kernel]) – The kernel used for the GP model.
measure (Optional[IntegrationMeasure]) – The integration measure.
domain (Optional[Union[Tuple[Union[float, Real, floating], Union[float, Real, floating]], Tuple[ndarray, ndarray]]]) – The integration bounds.
policy (str) – The policy choosing nodes at which to evaluate the integrand.
max_evals (Optional[Union[int, Integral, integer]]) – Maximum number of evaluations as stopping criterion.
var_tol (Optional[Union[float, Real, floating]]) – Variance tolerance as stopping criterion.
rel_tol (Optional[Union[float, Real, floating]]) – Relative tolerance as stopping criterion.
batch_size (Union[int, Integral, integer]) – Batch size used in node acquisition.
- Returns
An instance of this class.
- Return type
- Raises
ValueError – If Bayesian Monte Carlo (‘bmc’) is selected as
policy
and no random number generator (rng
) is given.NotImplementedError – If an unknown
policy
is given.
- has_converged(bq_state, info)[source]¶
Checks if the BQ method has converged.
- Parameters
bq_state (BQState) – State of the Bayesian quadrature methods. Contains all necessary information about the problem and the computation.
info (BQIterInfo) – Info on the BQ loop iteration.
- Returns
Whether the solver has converged.
- Return type
has_converged
- integrate(fun=None, nodes=None, fun_evals=None)[source]¶
Integrate the function
fun
.fun
may be analytically given, or numerically in terms offun_evals
at fixed nodes. This function calls the generatorbq_iterator
until the first stopping criterion is met.- Parameters
fun (Optional[Callable]) – Function to be integrated. It needs to accept a shape=(n_eval, input_dim)
np.ndarray
and return a shape=(n_eval,)np.ndarray
.nodes (Optional[ndarray]) – shape=(n_eval, input_dim) – Optional nodes at which function evaluations are available as
fun_evals
from start.fun_evals (Optional[ndarray]) – shape=(n_eval,) – Optional function evaluations at
nodes
available from the start.
- Returns
integral_belief – Posterior belief about the integral.
bq_state – Final state of the Bayesian quadrature method.
- Raises
ValueError – If neither the integrand function (
fun
) nor integrand evaluations (fun_evals
) are given.- Return type