Kernels#
This module implements gradient information into the Kernel structure provided by scikit-learn. This module is mostly based on the kernels module of the scikit-optimize package
- class kernels.Hyperparameter(name, value_type, bounds, max_length, n_elements=1, fixed=None, dynamic=None)[source]#
Bases:
HyperparameterA kernel hyperparameter’s specification in form of a namedtuple.
Note
We overwrite the whole class here since the namedtuple approach does not allow for easy extension. For more information on this see this link
- Attributes:
name (str) – The name of the hyperparameter. Note that a kernel using a hyperparameter with name “x” must have the attributes self.x and self.x_bounds
value_type (str) – The type of the hyperparameter. Currently, only “numeric” hyperparameters are supported.
bounds (pair of floats >= 0 or “fixed”) – The lower and upper bound on the parameter. If n_elements>1, a pair of 1d array with n_elements each may be given alternatively. If the string “fixed” is passed as bounds, the hyperparameter’s value cannot be changed.
n_elements (int, default=1) – The number of elements of the hyperparameter value. Defaults to 1, which corresponds to a scalar hyperparameter. n_elements > 1 corresponds to a hyperparameter which is vector-valued, such as, e.g., anisotropic length-scales.
fixed (bool, default=None) – Whether the value of this hyperparameter is fixed, i.e., cannot be changed during hyperparameter tuning. If None is passed, the “fixed” is derived based on the given bounds.
dynamic (bool, default=None) – Whether the value of this hyperparameter is dynamic, i.e. whether the bounds of the hyperparameter should automatically be adjusted to two orders of magnitude above and below the current best fit value. If None is passed, the “dynamic” is derived based on the given bounds.
max_length (float or array-like, shape = (n_dimensions,)) – The prior bounds of the posterior distribution (of the parameter-space, not the hyperparameter space) is required for hyperparameters which are length scales (correlation lengths) if their bounds are set to “dynamic”. This is done to restrict their range to the same order of magnitude as the prior size (actually 2x the prior).
- class kernels.Kernel[source]#
Bases:
KernelBase class for gpry kernels. Supports computation of the gradient of the kernel with respect to X
Note
This kernel class is taken entirely from the Scikit-optimize package.
- property hyperparameters#
Returns a list of all hyperparameter specifications.
- property bounds#
Returns the log-transformed bounds on the theta.
- Returns:
bounds – The log-transformed bounds on the kernel’s hyperparameters theta
- Return type:
ndarray of shape (n_dims, 2)
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.RBF(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), prior_bounds=None)[source]#
Bases:
Kernel,RBF- property hyperparameter_length_scale#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.Matern(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), nu=1.5, prior_bounds=None)[source]#
Bases:
Kernel,Matern- property hyperparameter_length_scale#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.RationalQuadratic(length_scale=1.0, alpha=1.0, length_scale_bounds=(1e-05, 100000.0), alpha_bounds=(1e-05, 100000.0), prior_bounds=None)[source]#
Bases:
Kernel,RationalQuadratic- property anisotropic#
- property hyperparameter_length_scale#
- property hyperparameter_alpha#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.ExpSineSquared(length_scale=1.0, periodicity=1.0, length_scale_bounds=(1e-05, 100000.0), periodicity_bounds=(1e-05, 100000.0), prior_bounds=None)[source]#
Bases:
Kernel,ExpSineSquared- property anisotropic#
- property hyperparameter_length_scale#
Returns the length scale
- property hyperparameter_periodicity#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.ConstantKernel(constant_value=1.0, constant_value_bounds=(1e-05, 100000.0))[source]#
Bases:
Kernel,ConstantKernel- property hyperparameter_constant_value#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.WhiteKernel(noise_level=1.0, noise_level_bounds=(1e-05, 100000.0))[source]#
Bases:
Kernel,WhiteKernel- property hyperparameter_noise_level#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.KernelOperator[source]#
Bases:
objectUpdated to accomodate the new kernel hyperparameter definition.
- property hyperparameters#
Returns a list of all hyperparameter.
- class kernels.Exponentiation(kernel, exponent)[source]#
Bases:
Kernel,Exponentiation- property hyperparameters#
Returns a list of all hyperparameter.
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.Sum(k1, k2)[source]#
Bases:
KernelOperator,Kernel,Sum- property hyperparameters#
Returns a list of all hyperparameter.
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.Product(k1, k2)[source]#
Bases:
KernelOperator,Kernel,Product- property hyperparameters#
Returns a list of all hyperparameter.
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)
- class kernels.DotProduct(sigma_0=1.0, sigma_0_bounds=(1e-05, 100000.0))[source]#
Bases:
Kernel,DotProduct- property hyperparameter_sigma_0#
- gradient_x(x, X_train)[source]#
Computes gradient of K(x, X_train) with respect to x
- Parameters:
x (array-like, shape=(n_features,)) – A single test point.
X_train (array-like, shape=(n_samples, n_features)) – Training data used to fit the gaussian process.
- Returns:
gradient_x – Gradient of K(x, X_train) with respect to x.
- Return type:
array-like, shape=(n_samples, n_features)