Covariance functions#

gpyreg.covariance_functions#

Each covariance function is implemented as a subclass of AbstractKernel, which defines their basic interface. An instance of one of these classes is passed to gpyreg.GP at initialization and defines the type of covariance function for that Gaussian process.

AbstractKernel#

class gpyreg.covariance_functions.AbstractKernel[source]#

Abstract base class for covariance kernels.

abstract compute(hyp: ndarray, X: ndarray, X_star: ndarray = None, compute_diag: bool = False, compute_grad: bool = False)[source]#

Compute the covariance matrix for given training points and test points.

Parameters:
hypndarray, shape (cov_N,)

A 1D array of hyperparameters, where cov_N is the number of hyperparameters.

Xndarray, shape (N, D)

A 2D array where each row is a training point.

X_starndarray, shape (M, D), optional

A 2D array where each row is a test point. If this is not given, the self-covariance matrix is being computed.

compute_diagbool, defaults to False

Whether to only compute the diagonal of the self-covariance matrix.

compute_gradbool, defaults to False

Whether to compute the gradient with respect to the hyperparameters.

Returns:
Kndarray

The covariance matrix which is by default of shape (N, N). If compute_diag = True the shape is (N,).

dKndarray, shape (N, N, cov_N), optional

The gradient of the covariance matrix with respect to the hyperparameters.

Raises:
ValueError

Raised when hyp has not the expected number of hyperparameters.

ValueError

Raised when hyp is not an 1D array but of higher dimension.

get_bounds_info(X: ndarray, y: ndarray)[source]#

Return information on the lower, upper, plausible lower and plausible upper bounds of the hyperparameters of this covariance function.

Parameters:
Xndarray, shape (N, D)

A 2D array where each row is a test point.

yndarray, shape (N, 1)

A 2D array where each row is a test target.

Returns:
cov_bound_info: dict

A dictionary containing the bound info with the following elements:

LBnp.ndarray, shape (cov_N, 1)

The lower bounds of the hyperparameters.

UBnp.ndarray, shape (cov_N, 1)

The upper bounds of the hyperparameters.

PLBnp.ndarray, shape (cov_N, 1)

The plausible lower bounds of the hyperparameters.

PUBnp.ndarray, shape (cov_N, 1)

The plausible upper bounds of the hyperparameters.

x0np.ndarray, shape (cov_N, 1)

The plausible starting point.

where cov_N is the number of hyperparameters.

hyperparameter_count(D: int)[source]#

Return the number of hyperparameters this covariance function has.

Parameters:
Dint

The dimensionality of the kernel.

Returns:
countint

The number of hyperparameters.

hyperparameter_info(D: int)[source]#

Return information on the names of hyperparameters for setting them in other parts of the program.

Parameters:
Dint

The dimensionality of the kernel.

Returns:
hyper_infoarray_like

A list of tuples of hyperparameter names and their number, in the order they are in the hyperparameter array.

RationalQuadraticARD#

class gpyreg.covariance_functions.RationalQuadraticARD[source]#

Bases: AbstractKernel

Rational Quadratic ARD kernel

compute(hyp: ndarray, X: ndarray, X_star: ndarray = None, compute_diag: bool = False, compute_grad: bool = False)[source]#

Compute the covariance matrix for given training points and test points.

Parameters:
hypndarray, shape (cov_N,)

A 1D array of hyperparameters, where cov_N is the number of hyperparameters.

Xndarray, shape (N, D)

A 2D array where each row is a training point.

X_starndarray, shape (M, D), optional

A 2D array where each row is a test point. If this is not given, the self-covariance matrix is being computed.

compute_diagbool, defaults to False

Whether to only compute the diagonal of the self-covariance matrix.

compute_gradbool, defaults to False

Whether to compute the gradient with respect to the hyperparameters.

Returns:
Kndarray

The covariance matrix which is by default of shape (N, N). If compute_diag = True the shape is (N,).

dKndarray, shape (N, N, cov_N), optional

The gradient of the covariance matrix with respect to the hyperparameters.

Raises:
ValueError

Raised when hyp has not the expected number of hyperparameters.

ValueError

Raised when hyp is not an 1D array but of higher dimension.

get_bounds_info(X: ndarray, y: ndarray)[source]#

Return information on the lower, upper, plausible lower and plausible upper bounds of the hyperparameters of this covariance function.

Parameters:
Xndarray, shape (N, D)

A 2D array where each row is a test point.

yndarray, shape (N, 1)

A 2D array where each row is a test target.

Returns:
cov_bound_info: dict

A dictionary containing the bound info with the following elements:

LBnp.ndarray, shape (cov_N, 1)

The lower bounds of the hyperparameters.

UBnp.ndarray, shape (cov_N, 1)

The upper bounds of the hyperparameters.

PLBnp.ndarray, shape (cov_N, 1)

The plausible lower bounds of the hyperparameters.

PUBnp.ndarray, shape (cov_N, 1)

The plausible upper bounds of the hyperparameters.

x0np.ndarray, shape (cov_N, 1)

The plausible starting point.

where cov_N is the number of hyperparameters.

hyperparameter_count(D: int)[source]#

Return the number of hyperparameters this covariance function has.

Parameters:
Dint

The dimensionality of the kernel.

Returns:
countint

The number of hyperparameters.

hyperparameter_info(D: int)[source]#

Return information on the names of hyperparameters for setting them in other parts of the program.

Parameters:
Dint

The dimensionality of the kernel.

Returns:
hyper_infoarray_like

A list of tuples of hyperparameter names and their number, in the order they are in the hyperparameter array.

Matern#

class gpyreg.covariance_functions.Matern(degree: int)[source]#

Bases: AbstractKernel

Matern kernel.

Parameters:
degree{1, 3, 5}

The degree of the Matern kernel.

Currently the only supported degrees are 1, 3, 5, and if some other degree is provided a ValueError exception is raised.

compute(hyp: ndarray, X: ndarray, X_star: ndarray = None, compute_diag: bool = False, compute_grad: bool = False)[source]#

Compute the covariance matrix for given training points and test points.

Parameters:
hypndarray, shape (cov_N,)

A 1D array of hyperparameters, where cov_N is the number of hyperparameters.

Xndarray, shape (N, D)

A 2D array where each row is a training point.

X_starndarray, shape (M, D), optional

A 2D array where each row is a test point. If this is not given, the self-covariance matrix is being computed.

compute_diagbool, defaults to False

Whether to only compute the diagonal of the self-covariance matrix.

compute_gradbool, defaults to False

Whether to compute the gradient with respect to the hyperparameters.

Returns:
Kndarray

The covariance matrix which is by default of shape (N, N). If compute_diag = True the shape is (N,).

dKndarray, shape (N, N, cov_N), optional

The gradient of the covariance matrix with respect to the hyperparameters.

Raises:
ValueError

Raised when hyp has not the expected number of hyperparameters.

ValueError

Raised when hyp is not an 1D array but of higher dimension.

SquaredExponential#

class gpyreg.covariance_functions.SquaredExponential[source]#

Bases: AbstractKernel

Squared exponential kernel.

compute(hyp: ndarray, X: ndarray, X_star: ndarray = None, compute_diag: bool = False, compute_grad: bool = False)[source]#

Compute the covariance matrix for given training points and test points.

Parameters:
hypndarray, shape (cov_N,)

A 1D array of hyperparameters, where cov_N is the number of hyperparameters.

Xndarray, shape (N, D)

A 2D array where each row is a training point.

X_starndarray, shape (M, D), optional

A 2D array where each row is a test point. If this is not given, the self-covariance matrix is being computed.

compute_diagbool, defaults to False

Whether to only compute the diagonal of the self-covariance matrix.

compute_gradbool, defaults to False

Whether to compute the gradient with respect to the hyperparameters.

Returns:
Kndarray

The covariance matrix which is by default of shape (N, N). If compute_diag = True the shape is (N,).

dKndarray, shape (N, N, cov_N), optional

The gradient of the covariance matrix with respect to the hyperparameters.

Raises:
ValueError

Raised when hyp has not the expected number of hyperparameters.

ValueError

Raised when hyp is not an 1D array but of higher dimension.