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.
- abstractmethod 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_Nis 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). Ifcompute_diag = Truethe shape is(N, 1).- 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.
- ValueError
Raised when compute_diag and compute_grad are both True: the gradient is available for the full covariance matrix only.
- ValueError
Raised when the kernel has periods and their number differs from the number of columns of X.
- 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_Nis 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(periods: ndarray = None)[source]#
Bases:
AbstractKernelRational Quadratic ARD kernel.
- Parameters:
- periodsarray_like, shape (D,), optional
The period of each input dimension along which the kernel is periodic, and
np.inffor each dimension along which it is not. Along a dimension of periodp, the squared differencedelta**2of two coordinates is replaced by the squared chord(p / pi)**2 * sin(pi * delta / p)**2, the squared distance between the two points mapped onto a circle of circumferencep. It is zero at every multiple of the period and equalsdelta**2to second order indelta, so that the length scale keeps the units of the input. The periods are fixed constants, not hyperparameters.None, the default, or periods that are all infinite give the non-periodic kernel. A period that is NaN, zero or negative, or periods that are not a one-dimensional array, raiseValueError.
- 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_Nis 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). Ifcompute_diag = Truethe shape is(N, 1).- 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.
- ValueError
Raised when compute_diag and compute_grad are both True: the gradient is available for the full covariance matrix only.
- ValueError
Raised when the kernel has periods and their number differs from the number of columns of X.
- 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_Nis 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, periods: ndarray = None)[source]#
Bases:
AbstractKernelMatern 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
ValueErrorexception is raised.- periodsarray_like, shape (D,), optional
The period of each input dimension along which the kernel is periodic, and
np.inffor each dimension along which it is not. Along a dimension of periodp, the squared differencedelta**2of two coordinates is replaced by the squared chord(p / pi)**2 * sin(pi * delta / p)**2, the squared distance between the two points mapped onto a circle of circumferencep. It is zero at every multiple of the period and equalsdelta**2to second order indelta, so that the length scale keeps the units of the input. The periods are fixed constants, not hyperparameters.None, the default, or periods that are all infinite give the non-periodic kernel. A period that is NaN, zero or negative, or periods that are not a one-dimensional array, raiseValueError.
- 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_Nis 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). Ifcompute_diag = Truethe shape is(N, 1).- 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.
- ValueError
Raised when compute_diag and compute_grad are both True: the gradient is available for the full covariance matrix only.
- ValueError
Raised when the kernel has periods and their number differs from the number of columns of X.
SquaredExponential#
- class gpyreg.covariance_functions.SquaredExponential(periods: ndarray = None)[source]#
Bases:
AbstractKernelSquared exponential kernel.
- Parameters:
- periodsarray_like, shape (D,), optional
The period of each input dimension along which the kernel is periodic, and
np.inffor each dimension along which it is not. Along a dimension of periodp, the squared differencedelta**2of two coordinates is replaced by the squared chord(p / pi)**2 * sin(pi * delta / p)**2, the squared distance between the two points mapped onto a circle of circumferencep. It is zero at every multiple of the period and equalsdelta**2to second order indelta, so that the length scale keeps the units of the input. The periods are fixed constants, not hyperparameters.None, the default, or periods that are all infinite give the non-periodic kernel. A period that is NaN, zero or negative, or periods that are not a one-dimensional array, raiseValueError.
- 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_Nis 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). Ifcompute_diag = Truethe shape is(N, 1).- 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.
- ValueError
Raised when compute_diag and compute_grad are both True: the gradient is available for the full covariance matrix only.
- ValueError
Raised when the kernel has periods and their number differs from the number of columns of X.