# Matern¶

class probnum.randprocs.kernels.Matern(input_shape, lengthscale=1.0, nu=1.5)

Matern kernel.

Covariance function defined by

$$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),$$

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 the ExpQuad kernel. A Gaussian process with Matern covariance function is $$\lceil \nu \rceil - 1$$ times differentiable.

Parameters

ExpQuad

Examples

>>> import numpy as np
>>> from probnum.randprocs.kernels import Matern
>>> K = Matern(input_shape=(), lengthscale=0.1, nu=2.5)
>>> xs = np.linspace(0, 1, 3)
>>> 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

 input_ndim Syntactic sugar for len(input_shape). input_shape Shape of single, i.e. non-batched, arguments of the covariance function. output_ndim Syntactic sugar for len(output_shape). output_shape Shape of single, i.e. non-batched, return values of the 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_ndim

Syntactic sugar for len(input_shape).

Return type

int

input_shape

Shape of single, i.e. non-batched, arguments of the covariance function.

Return type
output_ndim

Syntactic sugar for len(output_shape).

Return type

int

output_shape

Shape of single, i.e. non-batched, return values of the covariance function.

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

Return type

Methods Documentation

__call__(x0, x1)

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

The evaluation of the (cross-covariance) function(s) is vectorized over the batch shapes of the arguments, applying standard NumPy broadcasting.

Parameters
Returns

shape= bcast_batch_shape + output_shape – The (cross-)covariance function(s) evaluated at (x0, x1). Since the function is vectorized over the batch shapes of the inputs, the output array contains the following entries:

k_x0_x1[batch_idx + output_idx] = k[output_idx](
x0[batch_idx, ...],
x1[batch_idx, ...],
)


where we assume that x0 and x1 have been broadcast to a common shape bcast_batch_shape + input_shape, and where output_idx and batch_idx are indices compatible with output_shape and bcast_batch_shape, respectively. By k[output_idx] we refer to the covariance function at index output_idx in the tensor of covariance functions represented by the Kernel instance.

Return type

k_x0_x1

Raises

matrix

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

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 (stack) of pairwise covariances between two sets of input points. If k represents a single covariance function, then the resulting matrix will be symmetric positive-(semi)definite for x0 == x1.

Parameters
Returns

shape= batch_shape + output_shape – The matrix / stack of matrices containing the pairwise evaluations of the (cross-)covariance function(s) on x0 and x1. Depending on the shape of the inputs, batch_shape is either (M, N), (M,), (N,), or ().

Return type

kernmat

Raises

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

__call__
See documentation of class Kernel.