Polynomial

class probnum.randprocs.kernels.Polynomial(input_shape, constant=0.0, exponent=1.0)

Bases: Kernel

Polynomial kernel.

Covariance function defined by

\[k(x_0, x_1) = (x_0^\top x_1 + c)^q.\]
Parameters

See also

Linear

Linear covariance function.

Examples

>>> import numpy as np
>>> from probnum.randprocs.kernels import Polynomial
>>> K = Polynomial(input_shape=2, constant=1.0, exponent=3)
>>> xs = np.array([[1, -1], [-1, 0]])
>>> K.matrix(xs)
array([[27.,  0.],
       [ 0.,  8.]])

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).

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_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.

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 the Kernel.

  • x1 (Optional[ArrayLike]) – shape= batch_shape_1 + input_shape – (Batch of) input(s) for the second argument of the Kernel. Can also be set to None, in which case the function will behave as if x1 = 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 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
  • 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

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
  • x0 (ArrayLike) – shape= (M,) + input_shape or input_shape – Stack of inputs for the first argument of the Kernel.

  • x1 (Optional[ArrayLike]) – shape= (N,) + input_shape or input_shape – (Optional) stack of inputs for the second argument of the Kernel. If x1 is not specified, the function behaves as if x1 = 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) 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.

See also

__call__

Evaluate the kernel more flexibly.

Examples

See documentation of class Kernel.