gpflow.quadrature#

Modules#

Classes#

gpflow.quadrature.GaussianQuadrature#

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.

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[..., Tensor], Iterable[Callable[..., Tensor]]]) –

    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],
        usually [N_quad_points, N, d]
    f(X) shape: [N_quad_points, b1, b2, ...., bX, d'],
        usually [N_quad_points, N, 1] or [N_quad_points, N, d]
    

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

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

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

  • args (Any) – Passed to fun

  • kwargs (Any) – Passed to fun

Return type

Tensor

Returns

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

gpflow.quadrature.NDiagGHQuadrature#

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

Bases: gpflow.quadrature.base.GaussianQuadrature

Parameters
  • dim (int) –

  • n_gh (int) –

Functions#

gpflow.quadrature.hermgauss#

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

n (int) –

Return type

Tuple[ndarray[Any, Any], ndarray[Any, Any]]

gpflow.quadrature.mvhermgauss#

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.

Return type

Tuple[ndarray[Any, Any], ndarray[Any, Any]]

Returns

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

gpflow.quadrature.mvnquad#

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. :type means: Union[ndarray[Any, Any], Tensor, Variable, Parameter] :param means: NxD :type covs: Union[ndarray[Any, Any], Tensor, Variable, Parameter] :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. :type Dout: Optional[Tuple[int, ...]] :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). :rtype: Tensor :return: quadratures (N,*Dout)

Parameters

func (Callable[[Tensor], Tensor]) –

gpflow.quadrature.ndiag_mc#

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.

Fmu, Fvar, Ys should all have same shape, with overall size N.

Parameters
  • funcs (Union[Callable[..., Tensor], Iterable[Callable[..., Tensor]]]) – the integrand(s): Callable or Iterable of Callables that operates elementwise

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

  • Fmu (Union[ndarray[Any, Any], Tensor, Variable, Parameter]) – array/tensor

  • Fvar (Union[ndarray[Any, Any], Tensor, Variable, Parameter]) – array/tensor

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

  • Ys (Union[ndarray[Any, Any], Tensor, Variable, Parameter]) – arrays/tensors; deterministic arguments to be passed by name

  • epsilon (Union[ndarray[Any, Any], Tensor, Variable, Parameter, None]) –

Return type

Tensor

Returns

shape is the same as that of the first Fmu

gpflow.quadrature.ndiagquad#

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.

Fmu, Fvar, Ys should all have same shape, with overall size N.

Parameters
  • funcs (Union[Callable[..., Tensor], Iterable[Callable[..., Tensor]]]) – the integrand(s): Callable or Iterable of Callables that operates elementwise

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

  • Fmu (Union[ndarray[Any, Any], Tensor, Variable, Parameter, Tuple[Union[ndarray[Any, Any], Tensor, Variable, Parameter], ...], List[Union[ndarray[Any, Any], Tensor, Variable, Parameter]]]) – array/tensor or Din-tuple/list thereof

  • Fvar (Union[ndarray[Any, Any], Tensor, Variable, Parameter, Tuple[Union[ndarray[Any, Any], Tensor, Variable, Parameter], ...], List[Union[ndarray[Any, Any], Tensor, Variable, Parameter]]]) – 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 (Union[ndarray[Any, Any], Tensor, Variable, Parameter]) – arrays/tensors; deterministic arguments to be passed by name

Return type

Tensor

Returns

shape is the same as that of the first Fmu