Kernel Functions

Kernels for the Gaussian Process model

class src.magpy_rv.kernels.Cosine(hparams)[source]

Class that computes the Cosine kernel matrix.

Kernel formula:

\[K = H_1^2 \cos(\frac{2\pi \cdot |t-t'|}{H_2})\]

in which:

\(H_1\) = amp

\(H_2\) = per

Parameters

hparams – dictionary with all the hyperparameters. Should have 2 elements with possibly errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Cosine Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the cosine kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

class src.magpy_rv.kernels.ExpSinSquared(hparams)[source]

Class that computes the Exponential Sine Squared kernel matrix.

Kernel formula:

\[K = H_1^2 \cdot exp(-\frac{2}{H_3^2} \cdot \sin^2(\frac{\pi \cdot |t-t'|}{H_2}))\]

in which:

\(H_1\) = amp

\(H_3\) = recurrence timescale

\(H_2\) = period

Parameters

hparams – dictionary with all the hyperparameters. Should have 3 elements with possibly errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Exponential Sine Squared Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the periodic kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

class src.magpy_rv.kernels.ExpSquared(hparams)[source]

Class that computes the Exponential Squared kernel matrix.

Kernel formula:

\[K = H_1^2 \cdot exp(-\frac{1}{2} \frac{|t-t'|}{H_2^2})\]

in which:

\(H_1\) = amp

\(H_2\) = recurrence timescale

Parameters

hparams – dictionary with all the hyperparameters. Should have 2 elements with possibly errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Exponential Squared Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the ExpSquared kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

class src.magpy_rv.kernels.JitterQuasiPer(hparams)[source]

Class that computes the Quasi-periodic kernel matrix + jitter.

Kernel formula from Haywood Thesis 2016, Equation 2.14:

\[K = H_1^2 \cdot exp( \frac{-(t-t')^2}{H_2^2} - \frac{\sin^2(\frac{\pi(t-t')}{H_3}}{H_4^2} ) + \delta_{nm} jit^2\]

in which:

\(H_1\) = amp

\(H_2\) = explength

\(H_3\) = per

\(H_4\) = perlength

\(jit\) = jitter

Parameters

hparams – dictionary with all the hyperparameters. Should have 5 elements with errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Quasi-periodic Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the quasi-periodic kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

class src.magpy_rv.kernels.Kernel[source]

Parent class for all kernels. All new kernels should inherit from this class and follow its structure.

Each new kernel will require a __init__ method to override the parent class. In the __init__ function call the necessary hyperparamaters (generated with a dictionary).

abstract compute_covmatrix(errors)[source]

Computes the covariance matrix of the kernel

abstract static hparams()[source]

returns the list of hyperparameter names

class src.magpy_rv.kernels.Matern3(hparams)[source]

Class that computes the Matern 3/2 kernel matrix.

Kernel formula:

\[K = (H_1^2 \cdot (1 + \frac{\sqrt{3}|t-t'|}{H_2}) \cdot exp(\frac{\sqrt{3}|t-t'|}{H_2})) + \delta_{nm} jit^2\]

in which:

\(H_1\) = amp

\(H_2\) = timescale

\(jit\) = jitter

Parameters

hparams – dictionary with all the hyperparameters. Should have 3 elements with errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Quasi-periodic Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the matern 3/2 kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

class src.magpy_rv.kernels.Matern5(hparams)[source]

Class that computes the Matern 5/2 kernel matrix.

Kernel formula:

\[K = H_1^2 (1 + \frac{\sqrt{5}|t-t'|}{H_2} + 5|t-t'|^{\frac{2}{3}}H_2^2) exp(-\frac{\sqrt{5}|t-t'|}{H_2})\]

in which:

\(H_1\) = amp

\(H_2\) = timescale

Parameters

hparams – dictionary with all the hyperparameters. Should have 2 elements with errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Quasi-periodic Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the matern 5/2 kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

src.magpy_rv.kernels.PrintKernelList()[source]

Function to print the list of all currently available Kernels.

class src.magpy_rv.kernels.QuasiPer(hparams)[source]

Class that computes the Quasi-periodic kernel matrix.

Kernel formula from Haywood Thesis 2016, Equation 2.14:

\[K = H_1^2 \cdot exp( \frac{-(t-t')^2}{H_2^2} - \frac{\sin^2(\frac{\pi(t-t')}{H_3})}{H_4^2} )\]

in which:

\(H_1\) = amp

\(H_2\) = explength

\(H_3\) = per

\(H_4\) = perlength

Parameters

hparams – dictionary with all the hyperparameters. Should have 4 elements with errors

compute_covmatrix(dist_e, dist_se, errors=None)[source]

Function to compute the covariance matrix for the Quasi-periodic Kernel

Parameters
  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\), from the compute_distances function

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\), from the compute_distances function

  • errors (array, floats) – Array of the errors, if want to add to diagonal of the covariance matrix

Returns

covmatrix – Covariance matrix computed with the quasi-periodic kernel

Return type

matrix array, floats

static hparams(plotting=True)[source]

Function to return a list of the hyperparameters in selected format

Parameters

plotting (bool, optional) – True returns the list in format for plots, False returns the list in format for text, defaults to True

static name()[source]

Returns the name of the Kernel

src.magpy_rv.kernels.compute_distances(t1, t2)[source]

Function to compute the spatial distance between each x1 and x2 point in both euclidean and squared euclidean space.

Parameters
  • t1 (array or list, floats) – Array of the first time series

  • t2 (array or list, floats) – Array of the second time series

Returns

  • dist_e (array, floats) – Spatial distance between each x1-x2 points set in euclidean space in formula = \((t - t')\)

  • dist_se (array, floats) – Spatial distance between each x1-x2 points set in squared euclidean space in formula = \((t - t')^2\)

src.magpy_rv.kernels.defKernelList()[source]

Function to return the list of all currently available Kernels