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 [batch…].

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, batch..., d].
    f(X) shape: [N_quad_points, batch..., broadcast d].
    

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

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

    • mean has shape [batch…, D].

    Array/Tensor representing the mean of a d-Variate Gaussian distribution

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

    • var has shape [batch…, D].

    Array/Tensor representing the variance of a d-Variate Gaussian distribution

  • args (Any) – Passed to fun

  • kwargs (Any) – Passed to fun

Return type:

Tensor

Returns:

  • return has shape [batch…, broadcast D].

Gaussian log-expectation of the exponential of a function f

gpflow.quadrature.NDiagGHQuadrature#

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

Bases: 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:

  • return[0] has shape [n_quad_points, D].

  • return[1] has shape [n_quad_points].

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.

Parameters:
  • f – integrand function. Takes one input of shape ?xD.

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

  • Din (Optional[int]) – Number of input dimensions. Needs to be known at call-time.

  • Dout (Optional[Tuple[int, ...]]) – Number of output dimensions. Defaults to (). Dout is assumed to leave out the item index, i.e. f actually maps (?xD)->(?x*Dout).

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

    • means has shape [N, Din].

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

    • covs has shape [N, Din, Din].

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

Return type:

Tensor

Returns:

  • return has shape [N, Dout…].

quadratures

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]) –

    • Fmu has shape [N, Din].

    array/tensor

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

    • Fvar has shape [N, Din].

    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]) –

    • Ys.values() has shape [broadcast N, .].

    arrays/tensors; deterministic arguments to be passed by name

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

Return type:

Tensor

Returns:

  • return has shape [broadcast n_funs, N, P].

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]]]) –

    • Fmu has shape [broadcast Din, N…].

    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]]]) –

    • Fvar has shape [broadcast Din, N…].

    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]) –

    • Ys.values() has shape [N…].

    arrays/tensors; deterministic arguments to be passed by name

Return type:

Tensor

Returns:

  • return has shape [broadcast Dout, N…].

shape is the same as that of the first Fmu