smac.epm.gp_kernels module

class smac.epm.gp_kernels.ConstantKernel(constant_value: float = 1.0, constant_value_bounds: Tuple[float, float] = (1e-05, 100000.0), operate_on: Optional[numpy.ndarray] = None, prior: Optional[smac.epm.gp_base_prior.Prior] = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.ConstantKernel

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: Optional[numpy.ndarray] = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

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

Parameters
  • X (array, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y)

  • Y (array, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) if 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.epm.gp_kernels.HammingKernel(length_scale: Union[float, Tuple[float, ]] = 1.0, length_scale_bounds: Union[Tuple[float, float], List[Tuple[float, float]]] = (1e-05, 100000.0), operate_on: Optional[numpy.ndarray] = None, prior: Optional[smac.epm.gp_base_prior.Prior] = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.HammingKernel

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: Optional[numpy.ndarray] = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

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

Parameters
  • X ([array-like, shape=(n_samples_X, n_features)]) – Left argument of the returned kernel k(X, Y)

  • Y ([array-like, shape=(n_samples_Y, n_features) or None(default)]) – Right argument of the returned kernel k(X, Y). If None, k(X, X) if evaluated instead.

  • eval_gradient ([bool, False(default)]) – 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.

Returns

  • K ([array-like, shape=(n_samples_X, n_samples_Y)]) – Kernel k(X, Y)

  • K_gradient ([array-like, 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.

Note

Code partially copied from skopt (https://github.com/scikit-optimize). Made small changes to only compute necessary values and use scikit-learn helper functions.

class smac.epm.gp_kernels.MagicMixin[source]

Bases: object

_signature(func: Callable) → inspect.Signature[source]
clone_with_theta(theta: numpy.ndarray) → skopt.learning.gaussian_process.kernels.Kernel[source]

Returns a clone of self with given hyperparameters theta.

Parameters

theta (array, shape (n_dims,)) – The hyperparameters

get_params(deep: bool = True) → Dict[str, Any][source]

Get parameters of this kernel.

Parameters

deep (boolean, optional) – 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

mapping of string to any

property hyperparameters

Returns a list of all hyperparameter specifications.

property n_dims

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

prior: Optional[Prior] = None
set_active_dims(operate_on: Optional[numpy.ndarray] = None) → None[source]

Sets dimensions this kernel should work on

Parameters

operate_on (None, list or array, shape (n_dims,)) –

class smac.epm.gp_kernels.Matern(length_scale: Union[float, Tuple[float, ]] = 1.0, length_scale_bounds: Union[Tuple[float, float], List[Tuple[float, float]]] = (1e-05, 100000.0), nu: float = 1.5, operate_on: Optional[numpy.ndarray] = None, prior: Optional[smac.epm.gp_base_prior.Prior] = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.Matern

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: Optional[numpy.ndarray] = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

Return the kernel k(X, Y) and optionally its gradient. :param X: Left argument of the returned kernel k(X, Y) :type X: array, shape (n_samples_X, n_features) :param Y: Right argument of the returned kernel k(X, Y). If None, k(X, X)

if evaluated instead.

Parameters
  • 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.epm.gp_kernels.Product(k1: skopt.learning.gaussian_process.kernels.Kernel, k2: skopt.learning.gaussian_process.kernels.Kernel, operate_on: numpy.ndarray = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.Product

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: numpy.ndarray = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

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

Parameters
  • X (array, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y)

  • Y (array, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) if 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.epm.gp_kernels.RBF(length_scale: Union[float, Tuple[float, ]] = 1.0, length_scale_bounds: Union[Tuple[float, float], List[Tuple[float, float]]] = (1e-05, 100000.0), operate_on: Optional[numpy.ndarray] = None, prior: Optional[smac.epm.gp_base_prior.Prior] = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.RBF

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: Optional[numpy.ndarray] = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

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

Parameters
  • X (array, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y)

  • Y (array, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) if 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.epm.gp_kernels.Sum(k1: skopt.learning.gaussian_process.kernels.Kernel, k2: skopt.learning.gaussian_process.kernels.Kernel, operate_on: numpy.ndarray = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.Sum

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: numpy.ndarray = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

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

Parameters
  • X (array, shape (n_samples_X, n_features)) – Left argument of the returned kernel k(X, Y)

  • Y (array, shape (n_samples_Y, n_features), (optional, default=None)) – Right argument of the returned kernel k(X, Y). If None, k(X, X) if 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.epm.gp_kernels.WhiteKernel(noise_level: Union[float, Tuple[float, ]] = 1.0, noise_level_bounds: Union[Tuple[float, float], List[Tuple[float, float]]] = (1e-05, 100000.0), operate_on: Optional[numpy.ndarray] = None, prior: Optional[smac.epm.gp_base_prior.Prior] = None, has_conditions: bool = False)[source]

Bases: smac.epm.gp_kernels.MagicMixin, skopt.learning.gaussian_process.kernels.WhiteKernel

_abc_impl = <_abc_data object>
_call(X: numpy.ndarray, Y: Optional[numpy.ndarray] = None, eval_gradient: bool = False, active: Optional[numpy.ndarray] = None) → Union[numpy.ndarray, Tuple[numpy.ndarray, numpy.ndarray]][source]

Return the kernel k(X, Y) and optionally its gradient. :param X: Left argument of the returned kernel k(X, Y) :type X: array, shape (n_samples_X, n_features) :param Y: Right argument of the returned kernel k(X, Y). If None, k(X, X)

if evaluated instead.

Parameters
  • 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.

Returns

  • K (array, shape (n_samples_X, n_samples_Y)) – Kernel k(X, Y)

  • K_gradient (array (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.

smac.epm.gp_kernels.get_conditional_hyperparameters(X: numpy.ndarray, Y: Optional[numpy.ndarray]) → numpy.ndarray[source]