ProductMatern¶
- class probnum.randprocs.kernels.ProductMatern(input_shape, lengthscales, nus)¶
Bases:
KernelProduct Matern kernel.
Covariance function defined as a product of one-dimensional Matern kernels: \(k(x_0, x_1) = \prod_{i=1}^d k_i(x_{0,i}, x_{1,i})\), where \(x_0 = (x_{0,i}, \ldots, x_{0,d})\) and \(x_0 = (x_{0,i}, \ldots, x_{0,d})\) and \(k_i\) are one-dimensional Matern kernels.
- Parameters
input_shape (Union[int, Integral, integer, Iterable[Union[int, Integral, integer]]]) – Shape of the kernel’s input.
lengthscales (Union[ndarray, int, float, complex, Number, number]) – Lengthscales of the one-dimensional Matern kernels. Describes the input scale on which the process varies. If a scalar, the same lengthscale is used in each dimension.
nus (Union[ndarray, int, float, complex, Number, number]) – Hyperparameters controlling differentiability of the one-dimensional Matern kernels. If a scalar, the same smoothness is used in each dimension.
Examples
>>> import numpy as np >>> from probnum.randprocs.kernels import ProductMatern >>> lengthscales = np.array([0.1, 1.2]) >>> nus = np.array([0.5, 3.5]) >>> K = ProductMatern(input_shape=(2,), lengthscales=lengthscales, nus=nus) >>> xs = np.array([[0.0, 0.5], [1.0, 1.0], [0.5, 0.2]]) >>> K.matrix(xs) array([[1.00000000e+00, 4.03712525e-05, 6.45332482e-03], [4.03712525e-05, 1.00000000e+00, 5.05119251e-03], [6.45332482e-03, 5.05119251e-03, 1.00000000e+00]])
- Raises
ValueError – If kernel input is scalar, but
lengthscalesornusare not.- Parameters
Attributes Summary
Syntactic sugar for
len(input_shape).Shape of single, i.e. non-batched, arguments of the covariance function.
Syntactic sugar for
len(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).
- 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.
If
output_shapeis(), theKernelinstance represents a single (cross-)covariance function. Otherwise, i.e. ifoutput_shapeis non-empty, theKernelinstance represents a tensor of (cross-)covariance functions whose shape is given byoutput_shape.
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
x0 (ArrayLike) – shape=
batch_shape_0 +input_shape– (Batch of) input(s) for the first argument of theKernel.x1 (Optional[ArrayLike]) – shape=
batch_shape_1 +input_shape– (Batch of) input(s) for the second argument of theKernel. Can also be set toNone, in which case the function will behave as ifx1 = x0(but it is implemented more efficiently).
- 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
x0andx1have been broadcast to a common shapebcast_batch_shape +input_shape, and whereoutput_idxandbatch_idxare indices compatible withoutput_shapeandbcast_batch_shape, respectively. Byk[output_idx]we refer to the covariance function at indexoutput_idxin the tensor of covariance functions represented by theKernelinstance.- Return type
k_x0_x1
- Raises
ValueError – If one of the input shapes is not of the form
batch_shape_{0,1} +input_shape.ValueError – If the inputs can not be broadcast to a common shape.
See also
matrixConvenience 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. Ifkrepresents a single covariance function, then the resulting matrix will be symmetric positive-(semi)definite forx0 == x1.- Parameters
x0 (ArrayLike) – shape=
(M,) +input_shapeorinput_shape– Stack of inputs for the first argument of theKernel.x1 (Optional[ArrayLike]) – shape=
(N,) +input_shapeorinput_shape– (Optional) stack of inputs for the second argument of theKernel. Ifx1is not specified, the function behaves as ifx1 = x0(but it is implemented more efficiently).
- Returns
shape=
batch_shape +output_shape– The matrix / stack of matrices containing the pairwise evaluations of the (cross-)covariance function(s) onx0andx1. Depending on the shape of the inputs,batch_shapeis either(M, N),(M,),(N,), or().- Return type
kernmat
- 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.