Matern¶
- class probnum.kernels.Matern(input_dim, lengthscale=1.0, nu=1.5)¶
Bases:
probnum.kernels.Kernel
,probnum.kernels.IsotropicMixin
Matern kernel.
Covariance function defined by
\begin{equation} k(x_0, x_1) = \frac{1}{\Gamma(\nu) 2^{\nu - 1}} \left( \frac{\sqrt{2 \nu}}{l} \lVert x_0 - x_1 \rVert_2 \right)^\nu K_\nu \left( \frac{\sqrt{2 \nu}}{l} \lVert x_0 - x_1 \rVert_2 \right), \end{equation}where \(K_\nu\) is a modified Bessel function. The Matern kernel generalizes the
ExpQuad
kernel via its additional parameter \(\nu\) controlling the smoothness of the function. For \(\nu \rightarrow \infty\) the Matern kernel converges to theExpQuad
kernel. A Gaussian process with Matern covariance function is \(\lceil \nu \rceil - 1\) times differentiable.- Parameters
See also
ExpQuad
Exponentiated Quadratic / RBF kernel.
Examples
>>> import numpy as np >>> from probnum.kernels import Matern >>> K = Matern(input_dim=1, lengthscale=0.1, nu=2.5) >>> xs = np.linspace(0, 1, 3)[:, None] >>> K.matrix(xs) array([[1.00000000e+00, 7.50933789e-04, 3.69569622e-08], [7.50933789e-04, 1.00000000e+00, 7.50933789e-04], [3.69569622e-08, 7.50933789e-04, 1.00000000e+00]])
Attributes Summary
Dimension of arguments of the covariance function.
If
shape
is()
, theKernel
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
- shape¶
If
shape
is()
, theKernel
instance represents a single (cross-)covariance function. Otherwise, i.e. ifshape
is non-empty, theKernel
instance represents a tensor of (cross-)covariance functions whose shape is given byshape
.
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)
, whereD_in
is either1
orinput_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)
, whereD_in
is either1
orinput_dim
, whose entries will be passed to the second argument of the kernel. Can also be set toNone
, in which case the function will behave as ifx1 = x0
.
- Returns
k_x0_x1 – The (cross-)covariance function(s) evaluated at
x0
andx1
. Ifshape
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 inputsx0[ik, ..., i2, i1, :] and ``x1[il, ..., i2, i1, :])
. For any non-emptyshape
, it returns an array of shape(Sl, ..., S2, S1, Lk, ..., L2, L1)
, whereS
isshape
, whose entry at index(sl, ..., s2, s1, ik, ..., i2, i1)
contains evaluation of the (cross-)covariance function at index(sl, ..., s2, s1)
at the inputsx0[ik, ..., i2, i1, :]
andx1[ik, ..., i2, i1, :]
. Above, we assume thatx0
andx1
have been broadcast according to the rules described in the “Notes” section.- Return type
- 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, a1
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 toinput_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. Ifk
represents a covariance function, then the resulting matrix will be symmetric positive (semi-)definite forx0 == x1
.- Parameters
x0 (array-like) – First set of inputs to the (cross-)covariance function as an array of shape
(M, D)
, whereD
is either 1 orinput_dim
.x1 (array-like) – Optional second set of inputs to the (cross-)covariance function as an array of shape
(N, D)
, whereD
is either 1 orinput_dim
. Ifx1
is not specified, the function behaves as ifx1 = x0
.
- Returns
kernmat – The matrix / stack of matrices containing the pairwise evaluations of the (cross-)covariance function(s) on
x0
andx1
as an array of shape(M, N)
ifshape
is()
or(S[l - 1], ..., S[1], S[0], M, N)
, whereS
isshape
ifshape
is non-empty.- Return type
- 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
.