Isotropic covariance functions#
gpyreg.isotropic_covariance_functions#
The isotropic kernels use a single length scale for every input dimension, so they have two hyperparameters whatever the dimensionality. Each is implemented as a subclass of AbstractIsotropicKernel, which fixes those two hyperparameters and the bounds recommended for them (hyperparameter_count, hyperparameter_info and get_bounds_info), and of the kernel of the same family in gpyreg.covariance_functions, from which it inherits the rest, such as the degree of the Matern kernel; each defines its own compute. An instance is passed to gpyreg.GP at initialization in the same way as an anisotropic one.
AbstractIsotropicKernel#
- class gpyreg.isotropic_covariance_functions.AbstractIsotropicKernel[source]#
Bases:
AbstractKernelAbstract base class for isotropic kernel functions.
The two default hyperparameters are the log-lengthscale and log-outputscale.
- 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.
MaternIsotropic#
- class gpyreg.isotropic_covariance_functions.MaternIsotropic(degree: int)[source]#
Bases:
AbstractIsotropicKernel,MaternIsotropic Matern kernel.
Overrides compute. Inherits hyperparameter_count and hyperparameter_info from
AbstractIsotropicKernel. Inherits other methods fromMatern.- Parameters:
- degree{1, 3, 5}
The degree of the isotropic Matern kernel.
Currently the only supported degrees are 1, 3, 5, and if some other degree is provided a
ValueErrorexception 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_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.
SquaredExponentialIsotropic#
- class gpyreg.isotropic_covariance_functions.SquaredExponentialIsotropic[source]#
Bases:
AbstractIsotropicKernel,SquaredExponentialIsotropic squared exponential kernel.
Overrides compute. Inherits hyperparameter_count and hyperparameter_info from
AbstractIsotropicKernel. Inherits other methods fromSquaredExponential.- 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.