BayesianQuadrature¶
- class probnum.quad.BayesianQuadrature(kernel, measure, policy, belief_update, stopping_criterion)¶
Bases:
object
The Bayesian quadrature method.
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 (Optional[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
See also
bayesquad
Computes the integral using an acquisition policy.
bayesquad_from_data
Computes the integral \(F\) using a given dataset of nodes and function evaluations.
Methods Summary
bq_iterator
(bq_state, info, fun)Generator that implements the iteration of the BQ method.
from_problem
(input_dim[, kernel, measure, ...])Creates an instance of this class from a problem description.
integrate
(fun, nodes, fun_evals)Integrates the function
fun
.Methods Documentation
- bq_iterator(bq_state, info, fun)[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
bq_state (BQState) – State of the Bayesian quadrature methods. Contains the information about the problem and the BQ belief.
info (Optional[BQIterInfo]) – The state of the iteration.
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
.
- Yields
new_integral_belief – Updated belief about the integral.
new_bq_state – The updated state of the Bayesian quadrature belief.
new_info – The 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]¶
Creates an instance of this class from a problem description.
- Parameters
input_dim (int) – The input dimension.
kernel (Optional[Kernel]) – The kernel used for the GP model. Defaults to the
ExpQuad
kernel.measure (Optional[IntegrationMeasure]) – The integration measure. Defaults to the Lebesgue measure on the
domain
.domain (Optional[Union[Tuple[Union[float, Real, floating], Union[float, Real, floating]], Tuple[ndarray, ndarray]]]) – The integration bounds. Obsolete if
measure
is given.policy (Optional[str]) – The policy choosing nodes at which to evaluate the integrand. Choose
None
if you want to integrate from a fixed dataset.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 neither a
domain
nor ameasure
are given.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.
- integrate(fun, nodes, fun_evals)[source]¶
Integrates 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. It immediately stops after processing the initialnodes
ifpolicy
is not available.- 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.ValueError – If
nodes
are not given and no policy is present.ValueError – If dimension of
nodes
orfun_evals
is incorrect, or if their shapes do not match.
- Return type