GeneralKernel

Contents

GeneralKernel#

class luas.GeneralKernel(K: Callable | None = None, decomp_fn=None)[source]#

Bases: Kernel

Kernel object which solves for the log likelihood for any general kernel function K. Can also generate noise from K and can be used to compute the GP predictive mean and predictive covariance matrix conditioned on observed data.

Note

This method scales poorly in runtime and memory and is likely only appropriate for small data sets. If the covariance matrix K possesses structure which can be exploited for matrix decomposition then specifying a decomp_fn which can more efficiently return a Cholesky factor and log determinant of K could lead to significant runtime savings. The LuasKernel class should provide significant runtime savings if the covariance matrix has kronecker product structure in each dimension except in cases where one of the dimensions is very small or a sum of more than two kronecker products is needed.

>>> from luas import GeneralKernel, kernels
>>> def K_fn(hp, x_l1, x_l2, x_t1, x_t2, wn = True):
>>> ... Kl = hp["h"]**2*kernels.squared_exp(x_l1, x_l2, hp["l_l"])
>>> ... Kt = kernels.squared_exp(x_l1, x_l2, hp["l_t"])
>>> ... K = jnp.kron(Kl, Kt)
>>> ... return K
>>> kernel = GeneralKernel(K = K_fn)
... )
Parameters:
  • K (Callable, optional) – Function which returns the covariance matrix K.

  • decomp_fn (Callable, optional) – Function which given the covariance matrix K computes the Cholesky decomposition and log determinant of K. Defaults to luas.GeneralKernel.general_cholesky which performs Cholesky decomposition for any general covariance matrix.

GeneralKernel.decomp_fn(hp, x_l, x_t[, ...])

Builds the full covariance matrix K and uses the decomposition function specified at initialisation to return the Cholesky factor and the log determinant of K.

GeneralKernel.generate_noise(hp, x_l, x_t[, ...])

Generate noise with the covariance matrix returned by this kernel using the input hyperparameters hp.

GeneralKernel.logL(hp, x_l, x_t, R, ...)

Computes the log likelihood using Cholesky factorisation and also returns stored values from the matrix decomposition.

GeneralKernel.predict(hp, x_l, x_l_pred, ...)

Performs GP regression and computes the GP predictive mean and the GP predictive uncertainty as the standard devation at each location or else can return the full covariance matrix.

GeneralKernel.K_inv_by_vec(hp, x_l, x_t, R)

Calculates the product of the inverse of the covariance matrix with a vector, represented by a JAXArray of shape (N_l, N_t).

GeneralKernel.K_by_vec(hp, x_l, x_t, R)

Calculates the product of the covariance matrix with a vector, represented by a JAXArray of shape ``(N_l, N_t)`. Useful for testing for numerical stability.