RatQuad

class probnum.randprocs.kernels.RatQuad(input_dim, lengthscale=1.0, alpha=1.0)

Bases: probnum.randprocs.kernels.Kernel, probnum.randprocs.kernels.IsotropicMixin

Rational quadratic kernel.

Covariance function defined by

\begin{equation} k(x_0, x_1) = \left( 1 + \frac{\lVert x_0 - x_1 \rVert_2^2}{2 \alpha l^2} \right)^{-\alpha}, \end{equation}

where \(\alpha > 0\). For \(\alpha \rightarrow \infty\) the rational quadratic kernel converges to the ExpQuad kernel.

Parameters

See also

ExpQuad

Exponentiated Quadratic / RBF kernel.

Examples

>>> import numpy as np
>>> from probnum.randprocs.kernels import RatQuad
>>> K = RatQuad(input_dim=1, lengthscale=0.1, alpha=3)
>>> xs = np.linspace(0, 1, 3)[:, None]
>>> K(xs[:, None, :], xs[None, :, :])
array([[1.00000000e+00, 7.25051190e-03, 1.81357765e-04],
       [7.25051190e-03, 1.00000000e+00, 7.25051190e-03],
       [1.81357765e-04, 7.25051190e-03, 1.00000000e+00]])

Attributes Summary

input_dim

Dimension of arguments of the covariance function.

shape

If shape is (), the Kernel instance represents a single (cross-)covariance function.

Methods Summary

__call__(x0, x1)

Evaluate the (cross-)covariance function(s).

matrix(x0[, x1])

A convenience function for computing a kernel matrix for two sets of inputs.

Attributes Documentation

input_dim

Dimension of arguments of the covariance function.

Return type

int

shape

If shape is (), the Kernel instance represents a single (cross-)covariance function. Otherwise, i.e. if shape is non-empty, the Kernel instance represents a tensor of (cross-)covariance functions whose shape is given by shape.

Return type

Tuple[int, …]

Methods Documentation

__call__(x0, x1)

Evaluate the (cross-)covariance function(s).

The inputs are broadcast to a common shape following the “kernel broadcasting” rules outlined in the “Notes” section.

Parameters
  • x0 (array-like) – An array of shape () or (Nn, ..., N2, N1, D_in), where D_in is either 1 or input_dim, whose entries will be passed to the first argument of the kernel.

  • x1 (array-like) – An array of shape () or (Mm, ..., M2, M1, D_in), where D_in is either 1 or input_dim, whose entries will be passed to the second argument of the kernel. Can also be set to None, in which case the function will behave as if x1 = x0.

Returns

k_x0_x1 – The (cross-)covariance function(s) evaluated at x0 and x1. If shape is (), this method returns an array of shape (Lk, ..., L2, L1) whose entry at index (ik, ..., i2, i1) contains the evaluation of the (cross-)covariance function at the inputs x0[ik, ..., i2, i1, :] and ``x1[il, ..., i2, i1, :]). For any non-empty shape, it returns an array of shape (Sl, ..., S2, S1, Lk, ..., L2, L1), where S is shape, whose entry at index (sl, ..., s2, s1, ik, ..., i2, i1) contains evaluation of the (cross-)covariance function at index (sl, ..., s2, s1) at the inputs x0[ik, ..., i2, i1, :] and x1[ik, ..., i2, i1, :]. Above, we assume that x0 and x1 have been broadcast according to the rules described in the “Notes” section.

Return type

numpy.ndarray

Raises

ValueError – If the inputs can not be “kernel broadcast” to a common shape.

See also

matrix

Convenience function to compute a kernel matrix, i.e. a matrix of pairwise evaluations of the kernel on two sets of points.

Notes

A Kernel operates on its two inputs by a slightly modified version of Numpy’s broadcasting rules. First of all, the operation of the kernel is vectorized over all but the last dimension, applying standard broadcasting rules. An input with shape () is promoted to an input with shape (1,). Additionally, a 1 along the last axis of an input is interpreted as a (set of) point(s) with equal coordinates in all input dimensions, i.e. the inputs are broadcast to input_dim dimensions along the last axis. We refer to this modified set of broadcasting rules as “kernel broadcasting”.

Examples

See documentation of class Kernel.

matrix(x0, x1=None)

A convenience function for computing a kernel matrix for two sets of inputs.

This is syntactic sugar for k(x0[:, None, :], x1[None, :, :]). Hence, it computes the matrix of pairwise covariances between two sets of input points. If k represents a covariance function, then the resulting matrix will be symmetric positive (semi-)definite for x0 == x1.

Parameters
  • x0 (array-like) – First set of inputs to the (cross-)covariance function as an array of shape (M, D), where D is either 1 or input_dim.

  • x1 (array-like) – Optional second set of inputs to the (cross-)covariance function as an array of shape (N, D), where D is either 1 or input_dim. If x1 is not specified, the function behaves as if x1 = x0.

Returns

kernmat – The matrix / stack of matrices containing the pairwise evaluations of the (cross-)covariance function(s) on x0 and x1 as an array of shape (M, N) if shape is () or (S[l - 1], ..., S[1], S[0], M, N), where S is shape if shape is non-empty.

Return type

numpy.ndarray

Raises

ValueError – If the shapes of the inputs don’t match the specification.

See also

__call__

Evaluate the kernel more flexibly.

Examples

See documentation of class Kernel.