bayesquad¶
- probnum.quad.bayesquad(fun, input_dim, kernel=None, domain=None, measure=None, policy='bmc', max_evals=None, var_tol=None, rel_tol=None, batch_size=1, rng=Generator(PCG64) at 0x7F2DC3B84AC0)[source]¶
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]\).
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: \mathbb{R}^D \mapsto \mathbb{R}\).
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 (
int
) – Input dimension of the integration problem.kernel (
Optional
[Kernel
]) – The kernel used for the GP modeldomain (
Union
[Tuple
[Union
[float
,Real
,floating
],Union
[float
,Real
,floating
]],Tuple
[ndarray
,ndarray
],None
]) – shape=(input_dim,) – Domain of integration. Contains lower and upper bound asint
ornp.ndarray
.measure (
Optional
[IntegrationMeasure
]) – Integration measure. Defaults to the Lebesgue measure.Type of acquisition strategy to use. Options are
Bayesian Monte Carlo 2
bmc
max_evals (
Union
[int
,Integral
,integer
,None
]) – Maximum number of function evaluations.var_tol (
Union
[float
,Real
,floating
,None
]) – Tolerance on the variance of the integral.rel_tol (
Union
[float
,Real
,floating
,None
]) – Tolerance on consecutive updates of the integral mean.batch_size (
Union
[int
,Integral
,integer
,None
]) – Number of new observations at each update.rng (
Optional
[Generator
]) – Random number generator. Used by Bayesian Monte Carlo other random sampling policies. Optional. Default is np.random.default_rng().
- Return type
- Returns
integral – The integral of
fun
on the domain.info – Information on the performance of the method.
- Raises
ValueError – If neither a domain nor a measure are given.
ValueError – If a domain is given with a Gaussian measure.
References
- 1
Briol, F.-X., et al., Probabilistic integration: A role in statistical computation?, Statistical Science 34.1, 2019, 1-22, 2019
- 2
Rasmussen, C. E., and Z. Ghahramani, Bayesian Monte Carlo, Advances in Neural Information Processing Systems, 2003, 505-512.
Examples
>>> import numpy as np
>>> input_dim = 1 >>> domain = (0, 1) >>> def f(x): ... return x >>> F, info = bayesquad(fun=f, input_dim=input_dim, domain=domain) >>> print(F.mean) 0.5