class gpflow.quadrature.GaussianQuadrature[source]

Bases: object

Abstract class implementing quadrature methods to compute Gaussian Expectations. Inheriting classes must provide the method _build_X_W to create points and weights to be used for quadrature.

Methods

 __call__(fun, mean, var, *args, **kwargs) Compute the Gaussian Expectation of a function f: logspace(fun, mean, var, *args, **kwargs) Compute the Gaussian log-Expectation of a the exponential of a function f:
__call__(fun, mean, var, *args, **kwargs)[source]

Compute the Gaussian Expectation of a function f:

X ~ N(mean, var) E[f(X)] = ∫f(x, *args, **kwargs)p(x)dx

Using the formula:

E[f(X)] = sum_{i=1}^{N_quad_points} f(x_i) * w_i

where x_i, w_i must be provided by the inheriting class through self._build_X_W. The computations broadcast along batch-dimensions, represented by [b1, b2, …, bX].

Parameters
• fun

Callable or Iterable of Callables that operates elementwise, with signature f(X, *args, **kwargs). Moreover, it must satisfy the shape-mapping:

X shape: [N_quad_points, b1, b2, …, bX, d],

f(X) shape: [N_quad_points, b1, b2, …., bX, d’],

In most cases, f should only operate over the last dimension of X

• mean – Array/Tensor with shape [b1, b2, …, bX, d], usually [N, d], representing the mean of a d-Variate Gaussian distribution

• var – Array/Tensor with shape b1, b2, …, bX, d], usually [N, d], representing the variance of a d-Variate Gaussian distribution

• *args

Passed to fun

• **kargs

Passed to fun

Returns

Array/Tensor with shape [b1, b2, …., bX, d’], usually [N, d] or [N, 1]

logspace(fun, mean, var, *args, **kwargs)[source]

Compute the Gaussian log-Expectation of a the exponential of a function f:

X ~ N(mean, var) log E[exp[f(X)]] = log ∫exp[f(x, *args, **kwargs)]p(x)dx

Using the formula:

log E[exp[f(X)]] = log sum_{i=1}^{N_quad_points} exp[f(x_i) + log w_i]

where x_i, w_i must be provided by the inheriting class through self._build_X_W. The computations broadcast along batch-dimensions, represented by [b1, b2, …, bX].

Parameters
• fun (Union[Callable, Iterable[Callable]]) –

Callable or Iterable of Callables that operates elementwise, with signature f(X, *args, **kwargs). Moreover, it must satisfy the shape-mapping:

X shape: [N_quad_points, b1, b2, …, bX, d],

f(X) shape: [N_quad_points, b1, b2, …., bX, d’],

In most cases, f should only operate over the last dimension of X

• mean – Array/Tensor with shape [b1, b2, …, bX, d], usually [N, d], representing the mean of a d-Variate Gaussian distribution

• var – Array/Tensor with shape b1, b2, …, bX, d], usually [N, d], representing the variance of a d-Variate Gaussian distribution

• *args

Passed to fun

• **kargs

Passed to fun

Returns

Array/Tensor with shape [b1, b2, …., bX, d’], usually [N, d] or [N, 1]

class gpflow.quadrature.NDiagGHQuadrature(dim, n_gh)[source]

Bases: gpflow.quadrature.base.GaussianQuadrature

Methods

 __call__(fun, mean, var, *args, **kwargs) Compute the Gaussian Expectation of a function f: logspace(fun, mean, var, *args, **kwargs) Compute the Gaussian log-Expectation of a the exponential of a function f:
Parameters
• dim (int) –

• n_gh (int) –

__init__(dim, n_gh)[source]
Parameters
• dim (int) – dimension of the multivariate normal

• n_gh (int) – number of Gauss-Hermite points per dimension

_build_X_W(mean, var)[source]
Parameters
• mean (Union[Tensor, Variable, Parameter]) – Array/Tensor with shape [b1, b2, …, bX, dim], usually [N, dim], representing the mean of a dim-Variate Gaussian distribution

• var (Union[Tensor, Variable, Parameter]) – Array/Tensor with shape b1, b2, …, bX, dim], usually [N, dim], representing the variance of a dim-Variate Gaussian distribution

Returns

points X, Tensor with shape [n_gh_total, b1, b2, …, bX, dim], usually [n_gh_total, N, dim], and weights W, a Tensor with shape [n_gh_total, b1, b2, …, bX, 1], usually [n_gh_total, N, 1]

gpflow.quadrature.hermgauss(n)[source]
Parameters

n (int) –

gpflow.quadrature.mvhermgauss(H, D)[source]

Return the evaluation locations ‘xn’, and weights ‘wn’ for a multivariate Gauss-Hermite quadrature.

The outputs can be used to approximate the following type of integral: int exp(-x)*f(x) dx ~ sum_i w[i,:]*f(x[i,:])

Parameters
• H (int) – Number of Gauss-Hermite evaluation points.

• D (int) – Number of input dimensions. Needs to be known at call-time.

Returns

eval_locations ‘x’ (H**DxD), weights ‘w’ (H**D)

gpflow.quadrature.mvnquad(func, means, covs, H, Din=None, Dout=None)[source]

Computes N Gaussian expectation integrals of a single function ‘f’ using Gauss-Hermite quadrature. :param f: integrand function. Takes one input of shape ?xD. :param means: NxD :param covs: NxDxD :type H: int :param H: Number of Gauss-Hermite evaluation points. :type Din: Optional[int] :param Din: Number of input dimensions. Needs to be known at call-time. :param Dout: Number of output dimensions. Defaults to (). Dout is assumed to leave out the item index, i.e. f actually maps (?xD)->(?x*Dout). :return: quadratures (N,*Dout)

gpflow.quadrature.ndiag_mc(funcs, S, Fmu, Fvar, logspace=False, epsilon=None, **Ys)[source]

Computes N Gaussian expectation integrals of one or more functions using Monte Carlo samples. The Gaussians must be independent.

Parameters
• funcs – the integrand(s): Callable or Iterable of Callables that operates elementwise

• S (int) – number of Monte Carlo sampling points

• Fmu – array/tensor

• Fvar – array/tensor

• logspace (bool) – if True, funcs are the log-integrands and this calculates the log-expectation of exp(funcs)

• **Ys

arrays/tensors; deterministic arguments to be passed by name

Fmu, Fvar, Ys should all have same shape, with overall size N :return: shape is the same as that of the first Fmu

gpflow.quadrature.ndiagquad(funcs, H, Fmu, Fvar, logspace=False, **Ys)[source]

Computes N Gaussian expectation integrals of one or more functions using Gauss-Hermite quadrature. The Gaussians must be independent.

The means and variances of the Gaussians are specified by Fmu and Fvar. The N-integrals are assumed to be taken wrt the last dimensions of Fmu, Fvar.

Parameters
• funcs – the integrand(s): Callable or Iterable of Callables that operates elementwise

• H (int) – number of Gauss-Hermite quadrature points

• Fmu – array/tensor or Din-tuple/list thereof

• Fvar – array/tensor or Din-tuple/list thereof

• logspace (bool) – if True, funcs are the log-integrands and this calculates the log-expectation of exp(funcs)

• **Ys

arrays/tensors; deterministic arguments to be passed by name

Fmu, Fvar, Ys should all have same shape, with overall size N :return: shape is the same as that of the first Fmu