BayesianQuadrature

class probnum.quad.solvers.BayesianQuadrature(kernel, measure, policy, belief_update, stopping_criterion, initial_design)

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 Gaussian process 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.

  • initial_design (Optional[InitialDesign]) – The initial design chooses a set of nodes once, before the acquisition loop with the policy runs.

Raises:

ValueError – If initial_design is given but policy is not given.

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, rng)

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[, rng])

Integrates a given function.

Methods Documentation

bq_iterator(bq_state, info, fun, rng)[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 (BQIterInfo) – The state of the iteration.

  • fun (Callable | None) – Function to be integrated. It needs to accept a shape=(n_eval, input_dim) np.ndarray and return a shape=(n_eval,) np.ndarray.

  • rng (Generator | None) – The random number generator used for random methods.

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:

Tuple[Normal, BQState, BQIterInfo]

classmethod from_problem(input_dim, kernel=None, measure=None, domain=None, policy='bmc', initial_design=None, options=None)[source]

Creates an instance of this class from a problem description.

Parameters:
  • input_dim (IntLike) – The input dimension.

  • kernel (CovarianceFunction | None) – The kernel used for the GP model. Defaults to the ExpQuad kernel.

  • measure (IntegrationMeasure | None) – The integration measure. Defaults to the Lebesgue measure on the domain.

  • domain (DomainLike | None) – The integration bounds. Obsolete if measure is given.

  • policy (str | None) – The policy choosing nodes at which to evaluate the integrand. Choose None if you want to integrate from a fixed dataset.

  • initial_design (str | None) – The initial design chooses a set of nodes once, before the acquisition loop with the policy runs.

  • options (dict | None) –

    A dictionary with the following optional solver settings

    scale_estimationOptional[str]

    Estimation method to use to compute the scale parameter. Defaults to ‘mle’.

    max_evalsOptional[IntLike]

    Maximum number of evaluations as stopping criterion.

    var_tolOptional[FloatLike]

    Variance tolerance as stopping criterion.

    rel_tolOptional[FloatLike]

    Relative tolerance as stopping criterion.

    jitterOptional[FloatLike]

    Non-negative jitter to numerically stabilise kernel matrix inversion. Defaults to 1e-8.

    batch_sizeOptional[IntLike]

    Batch size used in node acquisition. Defaults to 1.

    n_initial_design_nodesOptional[IntLike]

    The number of nodes created by the initial design. Defaults to input_dim * 5 if an initial design is given.

    n_candidatesOptional[IntLike]

    The number of candidate nodes used by the policies that maximize an acquisition function by drawing random candidates. Defaults to 1e2. Applicable to policies ‘us_rand’, ‘mi_rand’ and ‘ivr_rand’.

    n_restartsOptional[IntLike]

    The number of restarts that the acquisition optimizer performs in order to find the maximizer. Defaults to 10. Applicable to policies ‘us’, ‘mi’ and ‘ivr’.

Returns:

An instance of this class.

Return type:

BayesianQuadrature

Raises:

See also

bayesquad :

For details on options for policy and initial_design.

integrate(fun, nodes, fun_evals, rng=None)[source]

Integrates a given function.

The function may be given as a function handle fun and/or numerically in terms of fun_evals at fixed nodes nodes.

If a policy is defined this method calls the generator bq_iterator until the first stopping criterion is met. The initial design is evaluated in a batch prior to running bq_iterator.

If no policy is defined this method immediately stops after processing the given nodes.

Parameters:
  • fun (Callable | None) – 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 (ndarray | None) – shape=(n_eval, input_dim) – Optional nodes at which function evaluations are available as fun_evals from start.

  • fun_evals (ndarray | None) – shape=(n_eval,) – Optional function evaluations at nodes available from the start.

  • rng (Generator | None) – The random number generator used for random methods.

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 dimension of nodes or fun_evals is incorrect, or if their shapes do not match.

  • ValueError – If rng is not given but policy or initial_design requires it.

  • ValueError – If a policy is available but fun is not given.

  • ValueError – If no policy is available and no nodes are given.

Warns:

UserWarning – When no policy is given and fun is ignored.

Return type:

Tuple[Normal, BQState, BQIterInfo]

Notes

The initial design is evaluated prior to running the bq_iterator and hence may not obey the stopping criterion. For example, if stopping is induced via a maximum number of evaluations (max_evals) smaller than the batch size of the initial design, the initial design will be evaluated nevertheless.