Gaussian Process Computations¶
The main interface to the celerite solver is through the GP class.
This main purpose of this class is to exposes methods for efficiently
computing the marginalized likelihood of a Gaussian Process (GP) model.
The covariance matrix for the GP will be specified by a kernel function as
described in the Kernel Building section.
The GP class implements the Python: Modeling with submodels called
kernel and mean so the modeling language can be used to fit for
parameters for each of these models.
Below, the methods of the GP object are described in detail but the
most important methods to look at are probably GP.compute(),
GP.log_likelihood(), and GP.predict().
-
class
celerite.GP(kernel, mean=0.0, fit_mean=False, log_white_noise=None, fit_white_noise=False)¶ The main interface to the celerite Gaussian Process solver
Parameters: - kernel – An instance of a subclass of
terms.Term. - mean (Optional) – A simple mean value for the process. This can either
be a
floator a subclass ofmodeling.Model. (default:0.0) - fit_mean (optional) – If
False, all of the parameters ofmeanwill be frozen. Otherwise, the parameter states are unaffected. (default:False)
-
apply_inverse(y)¶ Apply the inverse of the covariance matrix to a vector or matrix
Solve
K.x = yforxwhereKis the covariance matrix of the GP with the white noise andyerrcomponents included on the diagonal.Parameters: Returns: The solution to the linear system. This will have the same shape as
y.Return type: Raises: ValueError– For mismatched dimensions.
-
compute(t, yerr=1.123e-12, check_sorted=True, A=None, U=None, V=None)¶ Compute the extended form of the covariance matrix and factorize
Parameters: - x (array[n]) – The independent coordinates of the data points. This array must be _sorted_ in ascending order.
- yerr (Optional[float or array[n]]) – The measurement uncertainties
for the data points at coordinates
x. These values will be added in quadrature to the diagonal of the covariance matrix. (default:1.123e-12) - check_sorted (bool) – If
True,xwill be checked to make sure that it is properly sorted. IfFalse, the coordinates will be assumed to be in the correct order.
Raises: ValueError– For un-sorted data or mismatched dimensions.solver.LinAlgError– For non-positive definite matrices.
-
dot(y, t=None, A=None, U=None, V=None, kernel=None, check_sorted=True)¶ Dot the covariance matrix into a vector or matrix
Compute
K.ywhereKis the covariance matrix of the GP without the white noise oryerrvalues on the diagonal.Parameters: - y (array[n] or array[n, nrhs]) – The vector or matrix
ydescribed above. - kernel (Optional[terms.Term]) – A different kernel can optionally
be provided to compute the matrix
Kfrom a different kernel than thekernelproperty on this object.
Returns: The dot product
K.yas described above. This will have the same shape asy.Return type: Raises: ValueError– For mismatched dimensions.- y (array[n] or array[n, nrhs]) – The vector or matrix
-
get_matrix(x1=None, x2=None, include_diagonal=None, include_general=None)¶ Get the covariance matrix at given independent coordinates
Parameters: - x1 (Optional[array[n1]]) – The first set of independent coordinates.
If this is omitted,
x1will be assumed to be equal toxfrom a previous call toGP.compute(). - x2 (Optional[array[n2]]) – The second set of independent
coordinates. If this is omitted,
x2will be assumed to bex1. - include_diagonal (Optional[bool]) – Should the white noise and
yerrterms be included on the diagonal? (default:False)
- x1 (Optional[array[n1]]) – The first set of independent coordinates.
If this is omitted,
-
grad_log_likelihood(y, quiet=False)¶ Compute the gradient of the marginalized likelihood
The factorized matrix from the previous call to
GP.compute()is used socomputemust be called first. The gradient is taken with respect to the parameters returned byGP.get_parameter_vector(). This function requires the autograd package.Parameters: - y (array[n]) – The observations at coordinates
xfromGP.compute(). - quiet (bool) – If true, return
-numpy.infand a gradient vector of zeros for non-positive definite matrices instead of throwing an error.
Returns: The gradient of marginalized likelihood with respect to the parameter vector.
Raises: ValueError– For mismatched dimensions.solver.LinAlgError– For non-positive definite matrices.
- y (array[n]) – The observations at coordinates
-
log_likelihood(y, _const=1.8378770664093453, quiet=False)¶ Compute the marginalized likelihood of the GP model
The factorized matrix from the previous call to
GP.compute()is used socomputemust be called first.Parameters: - y (array[n]) – The observations at coordinates
xfromGP.compute(). - quiet (bool) – If true, return
-numpy.inffor non-positive definite matrices instead of throwing an error.
Returns: The marginalized likelihood of the GP model.
Return type: Raises: ValueError– For mismatched dimensions.solver.LinAlgError– For non-positive definite matrices.
- y (array[n]) – The observations at coordinates
-
mean¶ The mean
modeling.Model
-
predict(y, t=None, return_cov=True, return_var=False)¶ Compute the conditional predictive distribution of the model
You must call
GP.compute()before this method.Parameters: - y (array[n]) – The observations at coordinates
xfromGP.compute(). - t (Optional[array[ntest]]) – The independent coordinates where the
prediction should be made. If this is omitted the coordinates
will be assumed to be
xfromGP.compute()and an efficient method will be used to compute the prediction. - return_cov (Optional[bool]) – If
True, the full covariance matrix is computed and returned. Otherwise, only the mean prediction is computed. (default:True) - return_var (Optional[bool]) – If
True, only return the diagonal of the predictive covariance; this will be faster to compute than the full covariance matrix. This overridesreturn_covso, if both are set toTrue, only the diagonal is computed. (default:False)
Returns: mu,(mu, cov), or(mu, var)depending on the values ofreturn_covandreturn_var. These output values are: (a) mu(ntest,): mean of the predictive distribution, (b) cov(ntest, ntest): the predictive covariance matrix, and (c) var(ntest,): the diagonal elements ofcov.Raises: ValueError– For mismatched dimensions.- y (array[n]) – The observations at coordinates
-
sample(size=None)¶ Sample from the prior distribution over datasets
Parameters: size (Optional[int]) – The number of samples to draw. Returns: The samples from the prior distribution over datasets. Return type: array[n] or array[size, n]
-
sample_conditional(y, t=None, size=None)¶ Sample from the conditional (predictive) distribution
Note: this method scales as
O(M^3)for largeM, whereM == len(t).Parameters: - y (array[n]) – The observations at coordinates
xfromGP.compute(). - t (Optional[array[ntest]]) – The independent coordinates where the
prediction should be made. If this is omitted the coordinates
will be assumed to be
xfromGP.compute()and an efficient method will be used to compute the prediction. - size (Optional[int]) – The number of samples to draw.
Returns: The samples from the conditional distribution over datasets.
Return type: - y (array[n]) – The observations at coordinates
- kernel – An instance of a subclass of