profit.sur.gp.backend.python_kernels

Module which includes kernels for the Custom surrogate.

Module Contents

Functions

RBF(X, Y[, length_scale, sigma_f, sigma_n, eval_gradient])

Squared exponential kernel, also call Radial-Basis-Function kernel (RBF).

LinearEmbedding(X, Y, R[, sigma_f, sigma_n, eval_gradient])

The linear embedding kernel according to Garnett (2014) is a generalisation of the RBF kernel.

profit.sur.gp.backend.python_kernels.RBF(X, Y, length_scale=1, sigma_f=1, sigma_n=0, eval_gradient=False)[source]

Squared exponential kernel, also call Radial-Basis-Function kernel (RBF).

The RBF kernel is one of the most common kernels used and is especially suited for smooth functions.

\[ \begin{equation} K(X, Y) = \sigma_f^2 \exp(-\frac{1}{2} \frac{\lvert X-Y \rvert}{l^2}) + \sigma_n^2~\mathbf{1} \end{equation} \]

Parameters:
  • X (ndarray) – Input points.

  • Y (ndarray) – Other input points.

  • length_scale (float/ndarray) – Length scale \(l\) of the kernel function.

  • sigma_f (float) – Scale \(\sigma_f\).

  • sigma_n (float) – Additive noise \(\sigma_n\).

  • eval_gradient (bool) – Indicates if the gradient with respect to the hyperparameters \(l\), \(\sigma_f\) and \(\sigma_n\) should be returned.

Returns:

A tuple containing:
  • K (ndarray): Kernel matrix of size (X.shape[0], Y.shape[0]).

  • dK (ndarray): Derivative of the kernel w.r.t. the hyperparameters \(l\), \(\sigma_f\) and \(\sigma_n\).

If eval_gradient is False, only K is returned.

Return type:

tuple/ndarray

profit.sur.gp.backend.python_kernels.LinearEmbedding(X, Y, R, sigma_f=1e-06, sigma_n=0, eval_gradient=False)[source]

The linear embedding kernel according to Garnett (2014) is a generalisation of the RBF kernel.

The RBF kernel with different length scales in each dimension (ARD kernel) is a special case where only the diagonal elements of the matrix \(R\) are non-zero and represent inverse length scales. The ARD kernel is suited to detect relevant dimensions of the input data. In contrast, the linear embedding kernel can also detect relevant linear combinations of dimensions, e.g. if a function only varies in the direction \(x1 + x2\). Thus, the linear embedding kernel can be used to find a lower dimensional representation of the data in aribitrary directions.

\[ \begin{equation} K(X, Y) = \sigma_f^2 \exp(-\frac{1}{2} (X-Y)R^T R(X-Y)^T) + \sigma_n^2~\mathbf{1} \end{equation} \]

Here, we use the convention that the data \(X\) and \(Y\) are of shape (n, D) and therefore R has to be of shape (d, D) where D > d to find a lower dimensional representation.

Parameters:

X (ndarray): Input points of shape (n, D) Y (ndarray): Other input ponits. R (ndarray): Matrix or flattened array of hyperparameters. It is automatically reshaped to fit the input data.

Every matrix element represents a hyperparameter.

sigma_f (float): Scale \(\sigma_f\). sigma_n (float): Additive noise \(\sigma_n\). eval_gradient (bool): Indicates if the gradient with respect to the hyperparameters \(R_{ij}\), \(\sigma_f\) and

\(\sigma_n\) should be returned.

Returns:

A tuple containing:
  • K (ndarray): Kernel matrix of size (X.shape[0], Y.shape[0]).

  • dK (ndarray): Derivative of the kernel w.r.t. the hyperparameters \(R_{ij}\), \(\sigma_f\) and \(\sigma_n\).

If eval_gradient is False, only K is returned.

Return type:

tuple/ndarray