bayesquad

probnum.quad.bayesquad(fun, input_dim, kernel=None, measure=None, domain=None, policy='bmc', initial_design=None, rng=None, options=None)

Infer the solution of the uni- or multivariate integral \(\int_\Omega f(x) d \mu(x)\) on a hyper-rectangle \(\Omega = [a_1, b_1] \times \cdots \times [a_D, b_D]\) or \(\Omega = \mathbb{R}^D\).

Bayesian quadrature (BQ) infers integrals of the form

\[F = \int_\Omega f(x) d \mu(x),\]

of a function \(f:\mathbb{R}^D \mapsto \mathbb{R}\) integrated on the domain \(\Omega \subset \mathbb{R}^D\) against a measure \(\mu\) on \(\mathbb{R}^D\).

Bayesian quadrature methods return a probability distribution over the solution \(F\) with uncertainty arising from finite computation (here a finite number of function evaluations). They start out with a random process encoding the prior belief about the function \(f\) to be integrated. Conditioned on either existing or acquired function evaluations according to a policy, they update the belief on \(f\), which is translated into a posterior measure over the integral \(F\). See Briol et al. 1 for a review on Bayesian quadrature.

Parameters
  • fun (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.

  • input_dim (IntLike) – Input dimension of the integration problem.

  • kernel (Optional[CovarianceFunction]) – The kernel used for the GP model. Defaults to the ExpQuad kernel.

  • measure (Optional[IntegrationMeasure]) – The integration measure. Defaults to the Lebesgue measure on domain.

  • domain (Optional[DomainLike]) – The integration domain. Contains lower and upper bound as scalar or np.ndarray. Obsolete if measure is given.

  • policy (Optional[str]) –

    Type of acquisition strategy to use. Defaults to ‘bmc’. Options are

    Bayesian Monte Carlo 2

    bmc

    Van Der Corput points

    vdc

    Uncertainty Sampling with random candidates

    us_rand

    Uncertainty Sampling with optimizer

    us

    Mutual information with random candidates

    mi_rand

    Mutual information with optimizer

    mi

    Integral variance reduction with random candidates

    ivr_rand

    Integral variance reduction with optimizer

    ivr

  • initial_design (Optional[str]) –

    The type of initial design to use. If None is given, no initial design is used. Options are

    Samples from measure

    mc

    Latin hypercube 3

    latin

  • rng (Optional[Generator]) – The random number generator used for random methods.

  • options (Optional[dict]) –

    A dictionary with the following optional solver settings

    scale_estimationOptional[str]

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

    Maximum likelihood estimation

    mle

    max_evalsOptional[IntLike]

    Maximum number of function evaluations.

    var_tolOptional[FloatLike]

    Tolerance on the variance of the integral.

    rel_tolOptional[FloatLike]

    Tolerance on consecutive updates of the integral mean.

    jitterOptional[FloatLike]

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

    batch_sizeOptional[IntLike]

    Number of new observations at each update. 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

  • integral – The integral belief of \(F\) subject to the provided measure or domain.

  • info – Information on the performance of the method.

Raises

ValueError – If neither a domain nor a measure are given.

Warns

UserWarning – When domain is given but not used.

Return type

Tuple[Normal, BQIterInfo]

Notes

If multiple stopping conditions are provided, the method stops once one of them is satisfied. If no stopping condition is provided, the default values are max_evals = 25 * input_dim and var_tol = 1e-6.

See also

bayesquad_from_data

Computes the integral \(F\) using a given dataset of nodes and function evaluations.

Warning

Currently the method does not support tuning of the kernel parameters other than the global kernel scale. Hence, the method may perform poorly unless the kernel parameters are set to appropriate values by the user.

References

1

Briol, F.-X., et al., Probabilistic integration: A role in statistical computation?, Statistical Science 34.1, 2019, 1-22.

2

Rasmussen, C. E., and Z. Ghahramani, Bayesian Monte Carlo, Advances in Neural Information Processing Systems, 2003, 505-512.

3

Mckay et al., A Comparison of Three Methods for Selecting Values of Input Variables in the Analysis of Output from a Computer Code, Technometrics, 1979.

Examples

>>> import numpy as np
>>> input_dim = 1
>>> domain = (0, 1)
>>> def fun(x):
...     return x.reshape(-1, )
>>> F, info = bayesquad(fun, input_dim, domain=domain, rng=np.random.default_rng(0))
>>> print(F.mean)
0.5