The GP object

The core element of George is the GP object. All of the available methods and properties are documented here:

class george.GP(kernel=None, fit_kernel=True, mean=None, fit_mean=False, white_noise=-27.407877564614338, fit_white_noise=False, solver=None, **kwargs)

The basic Gaussian Process object.

Parameters:
  • kernel – An instance of a subclass of kernels.Kernel.
  • fit_kernel – (optional) If True, the parameters of the kernel will be included in all the relevant methods (get_vector(), grad_lnlikelihood(), etc.). (default: True)
  • mean – (optional) A description of the mean function. See mean for more information. (default: 0.0)
  • fit_mean – (optional) If True, the parameters of the mean function will be included in all the relevant methods (get_vector(), grad_lnlikelihood(), etc.). (default: False)
  • white_noise – (optional) A description of the logarithm of the white noise variance added to the diagonal of the covariance matrix. See white_noise for more information. (default: log(TINY))
  • fit_white_noise – (optional) If True, the parameters of white_noise will be included in all the relevant methods (get_vector(), grad_lnlikelihood(), etc.). (default: False)
  • solver – (optional) The solver to use for linear algebra as documented in Solvers.
  • kwargs – (optional) Any additional arguments are passed directly to the solver’s init function.
apply_inverse(y)

Self-consistently apply the inverse of the computed kernel matrix to some vector or matrix of samples. This method subtracts the mean, sorts the samples, then returns the samples in the correct (unsorted) order.

Parameters:y(nsamples, ) or (nsamples, K) The vector (or matrix) of sample values.
compute(x, yerr=1.25e-12, sort=True, **kwargs)

Pre-compute the covariance matrix and factorize it for a set of times and uncertainties.

Parameters:
  • x(nsamples,) or (nsamples, ndim) The independent coordinates of the data points.
  • yerr – (optional) (nsamples,) or scalar The Gaussian uncertainties on the data points at coordinates x. These values will be added in quadrature to the diagonal of the covariance matrix.
  • sort – (optional) Should the samples be sorted before computing the covariance matrix? This can lead to more numerically stable results and with some linear algebra libraries this can more computationally efficient. Either way, this flag is passed directly to parse_samples(). (default: True)
computed

Has the processes been computed since the last update of the kernel?

freeze_parameter(parameter_name)

Freeze (stop fitting for) a parameter by name. This name must be in the list returned by GP.get_parameter_names().

get_gradient(*args, **kwargs)

A synonym for GP.grad_lnlikelihood() provided for consistency with the modeling protocol.

get_matrix(x1, x2=None)

Get the covariance matrix at a given set or two of independent coordinates.

Parameters:
  • x1(nsamples,) or (nsamples, ndim) A list of samples.
  • x2(nsamples,) or (nsamples, ndim) (optional) A second list of samples. If this is given, the cross covariance matrix is computed. Otherwise, the auto-covariance is evaluated.
get_parameter_names()

Returns the list of parameter names following the modeling protocol. Parameters related to the mean function (included if fit_mean is True) are prefixed with mean:, parameters for the white noise function are prefixed with white:, and parameters for the kernel are prefixed with kernel:.

get_value(*args, **kwargs)

A synonym for GP.lnlikelihood() provided for consistency with the modeling protocol.

get_vector()

As specified by the modeling protocol, this returns the vector of fitting parameters for this model in the order specified by GP.get_parameter_names().

grad_lnlikelihood(y, quiet=False)

Compute the gradient of GP.lnlikelihood() as a function of the parameters returned by GP.get_vector(). You must call GP.compute() before this function.

Parameters:
  • y(nsamples,) The list of observations at coordinates x provided to the compute() function.
  • quiet – If True return a gradient of zero instead of raising an exception when there is an invalid kernel or linear algebra failure. (default: False)
lnlikelihood(y, quiet=False)

Compute the logarithm of the marginalized likelihood of a set of observations under the Gaussian process model. You must call GP.compute() before this function.

Parameters:
  • y(nsamples, ) The observations at the coordinates provided in the compute step.
  • quiet – If True return negative infinity instead of raising an exception when there is an invalid kernel or linear algebra failure. (default: False)
mean

An object (following the modeling protocol) that specifies the mean function of the GP. You can safely set this to a scalar, a callable, or an instance of a class satisfying the modeling protocol. In each case, the mean will be evaluated (either by calling the function or evaluating the get_value() method) at the input coordinates and it should return the one-dimensional mean evaluated at these coordinates.

parse_samples(t, sort=False)

Parse a list of samples to make sure that it has the correct dimensions and optionally sort it. In one dimension, the samples will be sorted in the logical order. In higher dimensions, a kd-tree is built and the samples are sorted in increasing distance from the first sample.

Parameters:
  • t(nsamples,) or (nsamples, ndim) The list of samples. If 1-D, this is assumed to be a list of one-dimensional samples otherwise, the size of the second dimension is assumed to be the dimension of the input space.
  • sort – (optional) A boolean flag indicating whether or not the samples should be sorted. (default: False)

Returns a tuple (samples, inds) where

  • samples is an array with shape (nsamples, ndim) and if sort was True, it will also be sorted, and
  • inds is an (nsamples,) list of integer permutations used to sort the list of samples.

Raises a RuntimeError if the input dimension doesn’t match the dimension of the kernel.

predict(y, t, return_cov=True, return_var=False)

Compute the conditional predictive distribution of the model. You must call GP.compute() before this function.

Parameters:
  • y(nsamples,) The observations to condition the model on.
  • t(ntest,) or (ntest, ndim) The coordinates where the predictive distribution should be computed.
  • return_cov – (optional) If True, the full covariance matrix is computed and returned. Otherwise, only the mean prediction is computed. (default: True)
  • return_var – (optional) If True, only return the diagonal of the predictive covariance; this will be faster to compute than the full covariance matrix. This overrides return_cov so, if both are set to True, only the diagonal is computed. (default: False)

Returns mu, (mu, cov), or (mu, var) depending on the values of return_cov and return_var. These output values are:

  • mu (ntest,): mean of the predictive distribution,
  • cov (ntest, ntest): the predictive covariance matrix, and
  • var (ntest,): the diagonal elements of cov.
recompute(quiet=False, **kwargs)

Re-compute a previously computed model. You might want to do this if the kernel parameters change and the kernel is labeled as dirty.

Parameters:quiet – (optional) If True, return false when the computation fails. Otherwise, throw an error if something goes wrong. (default: False)
sample(t=None, size=1)

Draw samples from the prior distribution.

Parameters:
  • t(ntest, ) or (ntest, ndim) (optional) The coordinates where the model should be sampled. If no coordinates are given, the precomputed coordinates and factorization are used.
  • size – (optional) The number of samples to draw. (default: 1)

Returns samples (size, ntest), a list of predictions at coordinates given by t. If size == 1, the result is a single sample with shape (ntest,).

sample_conditional(y, t, size=1)

Draw samples from the predictive conditional distribution. You must call GP.compute() before this function.

Parameters:
  • y(nsamples, ) The observations to condition the model on.
  • t(ntest, ) or (ntest, ndim) The coordinates where the predictive distribution should be computed.
  • size – (optional) The number of samples to draw. (default: 1)

Returns samples (size, ntest), a list of predictions at coordinates given by t.

set_vector(vector)

Update the model parameters given a vector in the order specified by GP.get_parameter_names().

thaw_parameter(parameter_name)

The opposite of GP.freeze_parameter(). Thaw (start fitting for) a parameter by name.

white_noise

An object (following the modeling protocol) that specifies the natural logarithm of the white noise variance added to the diagonal of the covariance matrix. You can safely set this to a scalar, a callable, or an instance of a class satisfying the modeling protocol. In each case, it will be evaluated (either by calling the function or evaluating the get_value() method) at the input coordinates and it should return the one-dimensional log-variance evaluated at these coordinates.

This functionality is preferred to the WhiteKernel class provided by earlier versions of this module.