# Polynomial¶

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

Polynomial kernel.

Covariance function defined by

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

Linear

Linear covariance function.

Examples

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


Attributes Summary

 input_dim Dimension of arguments of the covariance function. shape If shape is (), the Kernel 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

input_dim

Dimension of arguments of the covariance function.

Return type

int

shape

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

Return type

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), where D_in is either 1 or input_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), where D_in is either 1 or input_dim, whose entries will be passed to the second argument of the kernel. Can also be set to None, in which case the function will behave as if x1 = x0.

Returns

k_x0_x1 – The (cross-)covariance function(s) evaluated at x0 and x1. If shape 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 inputs x0[ik, ..., i2, i1, :] and x1[il, ..., i2, i1, :]). For any non-empty shape, it returns an array of shape (Sl, ..., S2, S1, Lk, ..., L2, L1), where S is shape, whose entry at index (sl, ..., s2, s1, ik, ..., i2, i1) contains evaluation of the (cross-)covariance function at index (sl, ..., s2, s1) at the inputs x0[ik, ..., i2, i1, :] and x1[ik, ..., i2, i1, :]. Above, we assume that x0 and x1 have been broadcast according to the rules described in the “Notes” section.

Return type

numpy.ndarray

Raises

ValueError – If the inputs can not be “kernel broadcast” to a common shape.

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, a 1 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 to input_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. If k represents a covariance function, then the resulting matrix will be symmetric positive (semi-)definite for x0 == x1.

Parameters
• x0 (array-like) – First set of inputs to the (cross-)covariance function as an array of shape (M, D), where D is either 1 or input_dim.

• x1 (array-like) – Optional second set of inputs to the (cross-)covariance function as an array of shape (N, D), where D is either 1 or input_dim. If x1 is not specified, the function behaves as if x1 = x0.

Returns

kernmat – The matrix / stack of matrices containing the pairwise evaluations of the (cross-)covariance function(s) on x0 and x1 as an array of shape (M, N) if shape is () or (S[l - 1], ..., S[1], S[0], M, N), where S is shape if shape is non-empty.

Return type

numpy.ndarray

Raises

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

__call__
See documentation of class Kernel.