User Reference

The GaussianProcess class

class gp_emulator.GaussianProcess(inputs=None, targets=None, emulator_file=None)

Bases: object

A simple class for Gaussian Process emulation. Currently, it assumes a squared exponential covariance function, but other covariance functions ought to be possible and easy to implement.

hessian(testing)

Calculates the hessian of the GP for the testing sample. hessian returns a (nn by d by d) array.

learn_hyperparameters(n_tries=15, verbose=False, x0=None)

User method to fit the hyperparameters of the model, using random initialisations of parameters. The user should provide a number of tries (e.g. how many random starting points to avoid local minima), and whether it wants lots of information to be reported back.

n_tries: int, optional
Number of random starting points
verbose: flag, optional
How much information to parrot (e.g. convergence of the minimisation algorithm)
x0: array, optional
If you want to start the learning process with a particular vector, set it up here.
loglikelihood(theta)

Calculates the loglikelihood for a set of hyperparameters theta. The size of theta is given by the dimensions of the input vector to the model to be emulated.

theta: array
Hyperparameters
partial_devs(theta)

This function calculates the partial derivatives of the cost function as a function of the hyperameters, and is only needed during GP training.

theta: array
Hyperparameter set
predict(testing, do_deriv=True, do_unc=True)

Make a prediction for a set of input vectors, as well as calculate the partial derivatives of the emulated model, and optionally, the “emulation uncertainty”.

testing: array, size Npred * Ninputs
The size of this array (and it must always be a 2D array!) is given by the number of input vectors that will be run through the emulator times the input vector size.
do_unc: flag, optional
Calculate the uncertainty (if you don’t set this flag, it can shave a few us.
do_deriv: flag, optional
Whether to calculate the partial derivatives of the emulated model.

Three parameters (the mean, the variance and the partial derivatives) If some of those outputs have been left out, they are returned as None elements.

save_emulator(emulator_file)

Save emulator to disk as npz FileExistsError Saves an emulator to disk using an npz file.

The MultivariateEmulator class

class gp_emulator.MultivariateEmulator(dump=None, X=None, y=None, hyperparams=None, model='', sza=0, vza=0, raa=0, thresh=0.98, n_tries=5)

Bases: object

calculate_decomposition(X, thresh)

Does PCA decomposition

This simply does a PCA decomposition using the SVD. Note that if X is very large, more efficient methods of doing this might be required. The number of PCs to retain is selected as those required to estimate thresh of the total variance.

X: array ( N_train, N_full )
The modelled output array for training
thresh: float
The threshold at where to cutoff the percentage of variance explained.
compress(X)

Project full-rank vector into PC basis

dump_emulator(fname, model_name, sza, vza, raa)

Save emulator to file for reuse

Saves the emulator to a file (.npz format) for reuse.

fname: str
The output filename
hessian(x)

A method to approximate the Hessian. This method builds on the fact that the spectral emulators are a linear combination of individual emulators. Therefore, we can calculate the Hessian of the spectral emulator as the sum of the individual products of individual Hessians times the spectral basis functions.

predict(y, do_unc=True, do_deriv=True)

Prediction of input vector

The individual GPs predict the PC weights, and these are used to reconstruct the value of the function at a point y. Additionally, the derivative of the function is also calculated. This is returned as a ( N_params, N_full ) vector (i.e., it needs to be reduced along axis 1)

Parameters: y: array

The value of the prediction point
do_deriv: bool
Whether derivatives are required or not
do_unc: bool
Whether to calculate the uncertainty or not

Returns: A tuple with the predicted mean, predicted variance and patial derivatives. If any of the latter two elements have been switched off by do_deriv or do_unc, they’ll be returned as None.

train_emulators(X, y, hyperparams, n_tries=2)

Train the emulators

This sets up the required emulators. If necessary (hypeparams is set to None), it will train the emulators.

X: array ( N_train, N_full )
The modelled output array for training
y: array (N_train, N_param )
The corresponding training parameters for X
hyperparams: array ( N_params + 2, N_PCs )
The hyperparameters for the relevant GPs