emukit.quadrature.methods package
Module contents
Bayesian quadrature models.
- class emukit.quadrature.methods.WarpedBayesianQuadratureModel(base_gp, warping, X, Y)
Bases:
IModel
,IDifferentiable
The general class for Bayesian quadrature (BQ) with a warped Gaussian process model.
The model is of the form \(f = w(g(x))\) where \(g\sim\mathcal{GP}\) is a Gaussian process and \(w:\mathbb{R}\rightarrow\mathbb{R}\) is a deterministic warping function.
Inherit from this class to create new warped Bayesian quadrature models.
See also
- property X: ndarray
The data nodes.
- property Y: ndarray
The data evaluations at the nodes.
- property integral_bounds: None | BoxDomain
The integration bounds.
None
if integration domain is not bounded.
- property reasonable_box_bounds: BoxDomain
Reasonable box bounds.
This box is used by the acquisition optimizer even when
integral_bounds
isNone
. By default it is set toget_box()
of the integration measure used, or, if not available, to theintegral_bounds
.See also
emukit.quadrature.measures.IntegrationMeasure.get_box
- property measure: None | IntegrationMeasure
The measure used for integration.
None
for standard Lebesgue measure.
- transform(Y)
The transform from base-GP to integrand implicitly defined by the warping used.
- Return type:
ndarray
- inverse_transform(Y)
The transform from integrand to base-GP implicitly defined by the warping used.
- Return type:
ndarray
- predict_base(X_pred)
Compute predictive means and variances of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim).- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and variances of warped GP, and predictive mean and variances of base-GP in that order all shapes (n_points, 1).
- predict_base_with_full_covariance(X_pred)
Compute predictive means and covariance of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim)- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and covariance of warped GP, predictive mean and covariance of base-GP in that order. mean shapes both (n_points, 1) and covariance shapes both (n_points, n_points)
- predict_with_full_covariance(X_pred)
Compute predictive means and covariance of warped GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim)- Return type:
Tuple
[ndarray
,ndarray
]- Returns:
predictive mean, predictive full covariance of warped-GP, shapes (n_points, 1) and (n_points, n_points)
- predict(X_pred)
Compute predictive means and variances of warped-GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim)- Return type:
Tuple
[ndarray
,ndarray
]- Returns:
predictive mean, predictive variances of warped-GP, both shapes (n_points, 1)
- set_data(X, Y)
Set the new data in the model.
First, potential warping parameters that are not being optimized but do depend on the data in an analytic way are updated. This is done via the method
compute_warping_params()
. Then, the new data is automatically transformed and set in the model.- Parameters:
X (
ndarray
) – Observation locations, shape (n_points, input_dim).Y (
ndarray
) – Integrand observations at X, shape (n_points, 1).
- Return type:
- compute_warping_params(X, Y)
Compute new parameters of the warping that are dependent on data, and that are not being optimized.
This method is called by default when new data is being set in
set_data()
. By default, this method returns an empty dict (no warping params need to be updated). Override this method in case warping parameters are data dependent.- Parameters:
X (
ndarray
) – Observation locations, shape (n_points, input_dim).Y (
ndarray
) – Integrand observations at X, shape (n_points, 1).
- Return type:
- Returns:
Dictionary containing new warping parameters. Names of parameters are the keys.
- integrate()
Compute an estimator of the integral as well as its variance.
- static symmetrize_matrix(A)
Symmetrize a matrix.
The symmetrized matrix is computed as \(A_{sym} = \frac{1}{2} (A + A^{\intercal})\).
- Parameters:
A (
ndarray
) – The square matrix \(A\), shape (N, N)- Return type:
ndarray
- Returns:
The symmetrized matrix \(A_{sym}\), shape (N, N).
- class emukit.quadrature.methods.VanillaBayesianQuadrature(base_gp, X, Y)
Bases:
WarpedBayesianQuadratureModel
Standard (‘vanilla’) Bayesian quadrature.
The warping for vanilla Bayesian quadrature is the identity transform \(w(y) = y\). Hence, the model for the integrand \(f\) is a standard Gaussian process as.
- Parameters:
base_gp (
IBaseGaussianProcess
) – The underlying Gaussian process model.X (
ndarray
) – The initial locations of integrand evaluations, shape (n_points, input_dim).Y (
ndarray
) – The values of the integrand at X, shape (n_points, 1).
- predict_base(X_pred)
Compute predictive means and variances of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim).- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and variances of warped GP, and predictive mean and variances of base-GP in that order all shapes (n_points, 1).
- predict_base_with_full_covariance(X_pred)
Compute predictive means and covariance of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim)- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and covariance of warped GP, predictive mean and covariance of base-GP in that order. mean shapes both (n_points, 1) and covariance shapes both (n_points, n_points)
- integrate()
Compute an estimator of the integral as well as its variance.
- class emukit.quadrature.methods.BoundedBayesianQuadrature(base_gp, X, Y, lower_bound=None, upper_bound=None)
Bases:
WarpedBayesianQuadratureModel
A warped Bayesian quadrature model that is upper bounded OR lower bounded by a constant.
The integrand \(f(x)\) is modeled as \(f(x) = f_* + \frac{1}{2} g(x)^2\) for lower bounded functions, or as \(f(x) = f^* - \frac{1}{2}g(x)^2\) for upper bounded functions. The constants \(f_*\) and \(f^*\) are the lower and upper bound respectively, and \(g\) is a Gaussian process (GP).
The process \(f\) induced by the Gaussian process \(g\) is non-Gaussian and not easy to integrate. In order to obtain an analytic estimator for the integral value, this class approximates the process \(f\) by another Gaussian process \(\hat{f}\) which is found by linearizing \(f\) around the mean of \(g\). It is then possible to integrate \(\hat{f}\) analytically. The approximate GP \(\hat{f}\) is implemented in the predict methods in this class, and it is also used by
integrate()
.- Parameters:
base_gp (
IBaseGaussianProcess
) – The Gaussian process \(g\). Must useemukit.quadrature.kernels.QuadratureRBFGaussianMeasure
as kernel.X (
ndarray
) – The initial locations of integrand evaluations, shape (n_point, input_dim).Y (
ndarray
) – The values of the integrand at X, shape (n_points, 1).lower_bound (
Optional
[float
]) – The lower bound \(f_*\) if the function is lower bounded.upper_bound (
Optional
[float
]) – The upper bound \(f^*\) if the function is lower bounded.
- Raises:
ValueError – If neither
lower_bound
norupper_bound
is given.ValueError – If both
lower_bound
andupper_bound
are given.ValueError – If the quadrature kernel of
base_gp
is not of typeQuadratureRBFGaussianMeasure
.
- property bound
The bound \(f^*\) or \(f_*\) as defined in the model.
- property is_lower_bounded
True
if the model is lower bounded,False
if it is upper bounded.
- predict_base(X_pred)
Compute predictive means and variances of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim).- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and variances of warped GP, and predictive mean and variances of base-GP in that order all shapes (n_points, 1).
- predict_base_with_full_covariance(X_pred)
Compute predictive means and covariance of the warped GP as well as the base GP.
- Parameters:
X_pred (
ndarray
) – Locations at which to predict, shape (n_points, input_dim)- Return type:
Tuple
[ndarray
,ndarray
,ndarray
,ndarray
]- Returns:
Predictive mean and covariance of warped GP, predictive mean and covariance of base-GP in that order. mean shapes both (n_points, 1) and covariance shapes both (n_points, n_points)
- integrate()
Compute an estimator of the integral as well as its variance.
- class emukit.quadrature.methods.WSABIL(base_gp, X, Y, adapt_alpha=True)
Bases:
BoundedBayesianQuadrature
Warped Sequential Active Bayesian Integration with linear approximation (WSABI-L).
The linear approximation is described in [1] in section 3.1, Eq (9) and (10).
The offset \(\alpha\) (notation from paper) will either be set to a small value if
adapt_alpha
isFalse
. Else it will be adapted according to \(0.8 \operatorname{min}(Y)\) as in Gunter et al. 2014, page 3, footnote, where \(Y\) are the collected integrand evaluations so far.References
[1] Gunter et al. 2014 Sampling for Inference in Probabilistic Models with Fast Bayesian Quadrature, Advances in Neural Information Processing Systems (NeurIPS), 27, pp. 2789–2797.
Note
WSABI-L must be used with the RBF kernel and the Gaussian integration measure (See description of
base_gp
parameter). The loop must use the uncertainty sampling acquisition strategy.See also
- Parameters:
base_gp (
IBaseGaussianProcess
) – A standard Gaussian process. Must useemukit.quadrature.kernels.QuadratureRBFGaussianMeasure
as kernel.X (
ndarray
) – The initial locations of integrand evaluations, shape (n_points, input_dim).Y (
ndarray
) – The values of the integrand at X, shape (n_points, 1).adapt_alpha (
bool
) – IfTrue
, the offset \(\alpha\) will be adapted. IfFalse
\(\alpha\) will be fixed to a small value for numerical stability. Default isTrue
.
Submodules
Warpings as used by warped Bayesian quadrature models.
- class emukit.quadrature.methods.warpings.Warping
Bases:
ABC
Base class for a warping as used by a warped Bayesian quadrature model.
See also
- abstract transform(Y)
Transform from base-GP to integrand.
- Parameters:
Y (
ndarray
) – Function values of latent function, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).
- abstract inverse_transform(Y)
Transform from integrand to base-GP.
- Parameters:
Y (
ndarray
) – Function values of integrand, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).
- class emukit.quadrature.methods.warpings.IdentityWarping
Bases:
Warping
The identity warping
\[w(y) = y.\]- transform(Y)
Transform from base-GP to integrand.
- Parameters:
Y (
ndarray
) – Function values of latent function, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).
- inverse_transform(Y)
Transform from integrand to base-GP.
- Parameters:
Y (
ndarray
) – Function values of integrand, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).
- class emukit.quadrature.methods.warpings.SquareRootWarping(offset, is_inverted=False)
Bases:
Warping
The square root warping.
\[\begin{split}w(y)=\begin{cases} c + \frac{1}{2}y^2 & \text{is_inverted is False (default)}\\ c - \frac{1}{2}y^2 &\text{otherwise} \end{cases},\end{split}\]where \(c\) is a constant.
- Parameters:
- transform(Y)
Transform from base-GP to integrand.
- Parameters:
Y (
ndarray
) – Function values of latent function, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).
- inverse_transform(Y)
Transform from integrand to base-GP.
- Parameters:
Y (
ndarray
) – Function values of integrand, shape (n_points, 1).- Return type:
ndarray
- Returns:
Transformed values, shape (n_points, 1).