smac.model.gaussian_process.kernels

Interfaces

class smac.model.gaussian_process.kernels.AbstractKernel(*, operate_on=None, has_conditions=False, prior=None, **kwargs)[source]

Bases: object

This is a mixin for a kernel to override functions of the kernel. Because it overrides functions of the kernel, it needs to be placed first in the inheritance hierarchy. For this reason it is not possible to subclass the Mixin from the kernel class because this will prevent it from being instantiatable. Therefore, mypy won’t know about anything related to the superclass and some type:ignore statements has to be added when accessing a member that is declared in the superclass such as self.has_conditions, self._call, super().get_params, etc.

Parameters:
  • operate_on (np.ndarray, defaults to None) – On which numpy array should be operated on.

  • has_conditions (bool, defaults to False) – Whether the kernel has conditions.

  • prior (AbstractPrior, defaults to None) – Which prior the kernel is using.

operate_on

On which numpy array should be operated on.

Type:

np.ndarray, defaults to None

has_conditions

Whether the kernel has conditions. Might be changed by the gaussian process.

Type:

bool, defaults to False

prior

Which prior the kernel is using. Primarily used by sklearn.

Type:

AbstractPrior, defaults to None

__call__(X, Y=None, eval_gradient=False, active=None)[source]

Call the kernel function. Internally, self._call is called, which must be specified by a subclass.

Return type:

ndarray | tuple[ndarray, ndarray]

get_params(deep=True)[source]

Get parameters of this kernel.

Parameters:

deep (bool, defaults to True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict[str, Any]

property hyperparameters: list[Hyperparameter]

Returns a list of all hyperparameter specifications.

property meta: dict[str, Any]

Returns the meta data of the created object. This method calls the get_params method to collect the parameters of the kernel.

property n_dims: int

Returns the number of non-fixed hyperparameters of the kernel.

class smac.model.gaussian_process.kernels.ConstantKernel(constant_value=1.0, constant_value_bounds=(1e-05, 100000.0), operate_on=None, has_conditions=False, prior=None)[source]

Bases: AbstractKernel, ConstantKernel

__call__(X, Y=None, eval_gradient=False, active=None)[source]

Return the kernel k(X, Y) and optionally its gradient.

Parameters:
  • X (np.ndarray, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y).

  • Y (np.ndarray, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.

  • eval_gradient (bool (optional, default=False)) – Determines whether the gradient with respect to the kernel hyperparameter is determined. Only supported when Y is None.

  • active (np.ndarray (n_samples_X, n_features) (optional)) – Boolean array specifying which hyperparameters are active.

Return type:

ndarray | tuple[ndarray, ndarray]

Returns:

  • K (np.ndarray, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y).

  • K_gradient (np.ndarray (opt.), shape (n_samples_X, n_samples_X, n_dims)) – The gradient of the kernel k(X, X) with respect to the hyperparameter of the kernel. Only returned when eval_gradient is True.

class smac.model.gaussian_process.kernels.HammingKernel(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), operate_on=None, has_conditions=False, prior=None)[source]

Bases: AbstractKernel, StationaryKernelMixin, NormalizedKernelMixin, Kernel

Hamming kernel implementation.

property hyperparameter_length_scale: Hyperparameter

Hyperparameter of the length scale.

property meta: dict[str, Any]

Returns the meta data of the created object. This method calls the get_params method to collect the parameters of the kernel.

class smac.model.gaussian_process.kernels.MaternKernel(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), nu=1.5, operate_on=None, has_conditions=False, prior=None)[source]

Bases: AbstractKernel, Matern

Matern kernel implementation.

class smac.model.gaussian_process.kernels.ProductKernel(k1, k2, operate_on=None, has_conditions=False)[source]

Bases: AbstractKernel, Product

Product kernel implementation.

__call__(X, Y=None, eval_gradient=False, active=None)[source]

Return the kernel k(X, Y) and optionally its gradient.

Parameters:
  • X (np.ndarray, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y).

  • Y (np.ndarray, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.

  • eval_gradient (bool (optional, default=False)) – Determines whether the gradient with respect to the kernel hyperparameter is determined.

  • active (np.ndarray (n_samples_X, n_features) (optional)) – Boolean array specifying which hyperparameters are active.

Return type:

ndarray | tuple[ndarray, ndarray]

Returns:

  • K (np.ndarray, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y).

  • K_gradient (np.ndarray (opt.), shape (n_samples_X, n_samples_X, n_dims)) – The gradient of the kernel k(X, X) with respect to the hyperparameter of the kernel. Only returned when eval_gradient is True.

class smac.model.gaussian_process.kernels.RBFKernel(length_scale=1.0, length_scale_bounds=(1e-05, 100000.0), operate_on=None, has_conditions=False, prior=None)[source]

Bases: AbstractKernel, RBF

RBF kernel implementation.

class smac.model.gaussian_process.kernels.SumKernel(k1, k2, operate_on=None, has_conditions=False)[source]

Bases: AbstractKernel, Sum

Sum kernel implementation.

__call__(X, Y=None, eval_gradient=False, active=None)[source]

Return the kernel k(X, Y) and optionally its gradient.

Parameters:
  • X (np.ndarray, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y).

  • Y (np.ndarray, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) is evaluated instead.

  • eval_gradient (bool (optional, default=False)) – Determines whether the gradient with respect to the kernel hyperparameter is determined.

  • active (np.ndarray (n_samples_X, n_features) (optional)) – Boolean array specifying which hyperparameters are active.

Return type:

ndarray | tuple[ndarray, ndarray]

Returns:

  • K (np.ndarray, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y).

  • K_gradient (np.ndarray (opt.), shape (n_samples_X, n_samples_X, n_dims)) – The gradient of the kernel k(X, X) with respect to the hyperparameter of the kernel. Only returned when eval_gradient is True.

class smac.model.gaussian_process.kernels.WhiteKernel(noise_level=1.0, noise_level_bounds=(1e-05, 100000.0), operate_on=None, has_conditions=False, prior=None)[source]

Bases: AbstractKernel, WhiteKernel

White kernel implementation.

Modules

smac.model.gaussian_process.kernels.base_kernels

smac.model.gaussian_process.kernels.hamming_kernel

smac.model.gaussian_process.kernels.matern_kernel

smac.model.gaussian_process.kernels.rbf_kernel

smac.model.gaussian_process.kernels.white_kernel