ExpQuad¶
- class probnum.kernels.ExpQuad(input_dim, lengthscale=1.0)¶
Bases:
probnum.kernels.Kernel,probnum.kernels.IsotropicMixinExponentiated quadratic / RBF kernel.
Covariance function defined by
\[k(x_0, x_1) = \exp \left( -\frac{\lVert x_0 - x_1 \rVert_2^2}{2 l^2} \right).\]This kernel is also known as the squared exponential or radial basis function kernel.
- Parameters
Examples
>>> import numpy as np >>> from probnum.kernels import ExpQuad >>> K = ExpQuad(input_dim=1, lengthscale=0.1) >>> xs = np.linspace(0, 1, 3)[:, None] >>> K.matrix(xs) array([[1.00000000e+00, 3.72665317e-06, 1.92874985e-22], [3.72665317e-06, 1.00000000e+00, 3.72665317e-06], [1.92874985e-22, 3.72665317e-06, 1.00000000e+00]])
Attributes Summary
Dimension of arguments of the covariance function.
If
shapeis(), theKernelinstance 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
shapeis(), theKernelinstance represents a single (cross-)covariance function. Otherwise, i.e. ifshapeis non-empty, theKernelinstance 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_inis either1orinput_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_inis either1orinput_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
x0andx1. Ifshapeis(), 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), whereSisshape, 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 thatx0andx1have 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
matrixConvenience function to compute a kernel matrix, i.e. a matrix of pairwise evaluations of the kernel on two sets of points.
Notes
A
Kerneloperates 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, a1along 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_dimdimensions 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. Ifkrepresents 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), whereDis either 1 orinput_dim.x1 (array-like) – Optional second set of inputs to the (cross-)covariance function as an array of shape
(N, D), whereDis either 1 orinput_dim. Ifx1is 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
x0andx1as an array of shape(M, N)ifshapeis()or(S[l - 1], ..., S[1], S[0], M, N), whereSisshapeifshapeis 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.