GpLinearInverter

class inference.gp.GpLinearInverter(y: ~numpy.ndarray, y_err: ~numpy.ndarray, model_matrix: ~numpy.ndarray, parameter_spatial_positions: ~numpy.ndarray, prior_covariance_function: ~inference.gp.covariance.CovarianceFunction = <class 'inference.gp.covariance.SquaredExponential'>, prior_mean_function: ~inference.gp.mean.MeanFunction = <class 'inference.gp.mean.ConstantMean'>)

A class for performing Gaussian-process linear inversion.

In the case where both the likelihood and prior distributions are multivariate normal, and the forward-model is linear, the posterior distribution is also multivariate normal, and the posterior mean and covariance can be calculated directly from the likelihood and prior mean and covariance.

If each of the model parameters can be associated with a position in some space (which is often the case in tomography and deconvolution problems) and we expect their values to be correlated within that space, we can model this behavior using a gaussian-process prior distribution.

Parameters
  • y – The y-data values as a 1D numpy.ndarray.

  • y_err – The error on the y-data values supplied as a 1D numpy.ndarray. These values are used to construct the likelihood covariance, which is assumed to be diagonal.

  • model_matrix – The linear forward-model as a 2D numpy.ndarray. The product of this model matrix with a vector of model parameter values should yield a prediction of the y-data values.

  • parameter_spatial_positions – A 2D numpy.ndarray specifying the ‘positions’ of the model parameters in some space over which their values are expected to be correlated.

  • prior_covariance_function (class) – A covariance function class which will be used to generate the prior covariance. Covariance function classes can be found in the gp module, or custom covariance functions can be written using the CovarianceFunction abstract base class.

  • prior_mean_function (class) – A mean function class which will be used to generate the prior mean. Mean function classes can be found in the gp module, or custom mean functions can be written using the MeanFunction abstract base class.

calculate_posterior(theta: ndarray)

Calculate the posterior mean and covariance for the given hyper-parameter values.

Parameters

theta – The hyper-parameter values as a 1D numpy.ndarray.

Returns

The posterior mean and covariance.

calculate_posterior_mean(theta: ndarray) ndarray

Calculate the posterior mean for the given hyper-parameter values.

Parameters

theta – The hyper-parameter values as a 1D numpy.ndarray.

Returns

The posterior mean and covariance.

marginal_likelihood(theta: ndarray) float

Calculate the log-marginal likelihood for the given hyper-parameter values.

Parameters

theta – The hyper-parameter values as a 1D numpy.ndarray.

Returns

The log-marginal likelihood value.

optimize_hyperparameters(initial_guess: ndarray) ndarray

Finds the hyper-parameter values which maximise the marginal-likelihood.

Parameters

initial_guess – An initial guess for the hyper-parameter values as a 1D numpy.ndarray.

Returns

The hyper-parameters which maximise the marginal-likelihood as a 1D numpy.ndarray.

Example code

Example code can be found in the Gaussian-process linear inversion jupyter notebook demo.