ab.kernels

Random kernel classes for use with the RandomKernel layers.

class aboleth.kernels.Matern(lenscale=None, learn_lenscale=False, p=1, seed=0)

Bases: aboleth.kernels.ShiftInvariant

Matern kernel approximation.

Parameters:
  • lenscale (float, ndarray, optional) – The length scales of the Matern kernel. This can be a scalar for an isotropic kernel, or a vector of shape (input_dim,) for an automatic relevance detection (ARD) kernel. If not provided, it will be set to sqrt(1 / input_dim) (this is similar to the ‘auto’ setting for a scikit learn SVM with a RBF kernel). If learn_lenscale is True, lenscale will be its initial value.
  • learn_lenscale (bool, optional) – Whether to learn the length scale. If True, the lenscale value provided (or its default) is used for initialisation.
  • p (int) – a zero or positive integer specifying the number of the Matern kernel, e.g. p == 0 results int a Matern 1/2 kernel, p == 1 results in the Matern 3/2 kernel etc.
  • seed (int, optional) – The seed for the internal random number generator. Setting a fixed seed ensures that remaking the tensorflow graph results in the same weights.
weights(input_dim, n_features, dtype=<class 'numpy.float32'>)

Generate the random fourier weights for this kernel.

Parameters:
  • input_dim (int) – the input dimension to this layer.
  • n_features (int) – the number of unique random features, the actual output dimension of this layer will be 2 * n_features.
  • dtype (np.dtype) – the dtype of the features to draw, this should match the observations.
Returns:

  • P (ndarray) – the random weights of the fourier features of shape (input_dim, n_features).
  • KL (Tensor, float) – the KL penalty associated with the parameters in this kernel (0.0).

class aboleth.kernels.RBF(lenscale=None, learn_lenscale=False, seed=0)

Bases: aboleth.kernels.ShiftInvariant

Radial basis kernel approximation.

Parameters:
  • lenscale (float, ndarray, optional) – The length scales of the RBF kernel. This can be a scalar for an isotropic kernel, or a vector of shape (input_dim,) for an automatic relevance detection (ARD) kernel. If not provided, it will be set to sqrt(1 / input_dim) (this is similar to the ‘auto’ setting for a scikit learn SVM with a RBF kernel). If learn_lenscale is True, lenscale will be its initial value.
  • learn_lenscale (bool, optional) – Whether to learn the length scale. If True, the lenscale value provided (or its default) is used for initialisation.
  • seed (int, optional) – The seed for the internal random number generator. Setting a fixed seed ensures that remaking the tensorflow graph results in the same weights.
weights(input_dim, n_features, dtype=<class 'numpy.float32'>)

Generate the random fourier weights for this kernel.

Parameters:
  • input_dim (int) – the input dimension to this layer.
  • n_features (int) – the number of unique random features, the actual output dimension of this layer will be 2 * n_features.
  • dtype (np.dtype) – the dtype of the features to draw, this should match the observations.
Returns:

  • P (ndarray) – the random weights of the fourier features of shape (input_dim, n_features).
  • KL (Tensor, float) – the KL penalty associated with the parameters in this kernel (0.0).

class aboleth.kernels.RBFVariational(lenscale=None, learn_lenscale=False, seed=0)

Bases: aboleth.kernels.ShiftInvariant

Variational Radial basis kernel approximation.

This kernel is similar to the RBF kernel, however we learn an independant Gaussian posterior distribution over the kernel weights to sample from.

Parameters:
  • lenscale (float, ndarray, optional) – The length scales of the RBF kernel. This can be a scalar for an isotropic kernel, or a vector of shape (input_dim,) for an automatic relevance detection (ARD) kernel. If not provided, it will be set to sqrt(1 / input_dim) (this is similar to the ‘auto’ setting for a scikit learn SVM with a RBF kernel). If learn_lenscale is True, lenscale will be the initial value of the prior precision of the Fourier weight distribution.
  • learn_lenscale (bool, optional) – Whether to learn the (prior) length scale. If True, the lenscale value provided (or its default) is used for initialisation.
  • seed (int, optional) – The seed for the internal random number generator. Setting a fixed seed ensures that remaking the tensorflow graph results in the same weights.
weights(input_dim, n_features, dtype=<class 'numpy.float32'>)

Generate the random fourier weights for this kernel.

Parameters:
  • input_dim (int) – the input dimension to this layer.
  • n_features (int) – the number of unique random features, the actual output dimension of this layer will be 2 * n_features.
  • dtype (np.dtype) – the dtype of the features to draw, this should match the observations.
Returns:

  • P (ndarray) – the random weights of the fourier features of shape (input_dim, n_features).
  • KL (Tensor, float) – the KL penalty associated with the parameters in this kernel.

class aboleth.kernels.ShiftInvariant(lenscale=None, learn_lenscale=False, seed=0)

Bases: object

Abstract base class for shift invariant kernel approximations.

Parameters:
  • lenscale (float, ndarray, optional) – The length scales of the shift invariant kernel. This can be a scalar for an isotropic kernel, or a vector of shape (input_dim,) for an automatic relevance detection (ARD) kernel. If learn_lenscale is True, lenscale will be its initial value.
  • learn_lenscale (bool, optional) – Whether to learn the length scale. If True, the lenscale value provided (or its default) is used for initialisation.
  • seed (int, optional) – The seed for the internal random number generator. Setting a fixed seed ensures that remaking the tensorflow graph results in the same weights.
weights(input_dim, n_features, dtype=<class 'numpy.float32'>)

Generate the random fourier weights for this kernel.

Parameters:
  • input_dim (int) – the input dimension to this layer.
  • n_features (int) – the number of unique random features, the actual output dimension of this layer will be 2 * n_features.
  • dtype (np.dtype) – the dtype of the features to draw, this should match the observations.
Returns:

  • P (ndarray) – the random weights of the fourier features of shape (input_dim, n_features).
  • KL (Tensor, float) – the KL penalty associated with the parameters in this kernel.