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, mean=None, solver=<class 'george.basic.BasicSolver'>, **kwargs)¶
The basic Gaussian Process object.
Parameters: - kernel – An instance of a subclass of kernels.Kernel.
- mean – (optional) A description of the mean function; can be a callable or a scalar. If scalar, the mean is assumed constant. Otherwise, the function will be called with the array of independent coordinates as the only argument. (default: 0.0)
- 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.
- 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?
- get_matrix(t)¶
Get the covariance matrix at a given set of independent coordinates.
Parameters: t – (nsamples,) or (nsamples, ndim) The list of samples.
- grad_lnlikelihood(y, quiet=False)¶
Compute the gradient of the ln-likelihood function as a function of the kernel parameters.
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 ln-likelihood of a set of observations under the Gaussian process model. You must call 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)
- optimize(x, y, yerr=1.25e-12, sort=True, dims=None, verbose=True, **kwargs)¶
A simple and not terribly robust non-linear optimization algorithm for the kernel hyperpararmeters.
Parameters: - x – (nsamples,) or (nsamples, ndim) The independent coordinates of the data points.
- y – (nsamples, ) The observations at the coordinates x.
- 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?
- dims – (optional) If you only want to optimize over some parameters, list their indices here.
- verbose – (optional) Display the results of the call to scipy.optimize.minimize()? (default: True)
Returns (pars, results) where pars is the list of optimized parameters and results is the results object returned by scipy.optimize.minimize().
- 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 – A boolean flag indicating whether or not the samples should be sorted.
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, mean_only=False)¶
Compute the conditional predictive distribution of the model.
Parameters: - y – (nsamples,) The observations to condition the model on.
- t – (ntest,) or (ntest, ndim) The coordinates where the predictive distribution should be computed.
Returns a tuple (mu, cov) where
- mu (ntest,) is the mean of the predictive distribution, and
- cov (ntest, ntest) is the predictive covariance.
- 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.
- 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.
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 (N, ntest), a list of predictions at coordinates given by t.