Covariance calculations for Gaussian process kernels. Currently supports matern, rbf, compact1, periodicMatern, generalMatern, and rationalQuadratic kernels. Can also return m_phi and other additional quantities useful for ODE inference.
calCov(
phi,
rInput,
signrInput,
bandsize = NULL,
complexity = 3,
kerneltype = "matern",
df,
noiseInjection = 1e-07
)A list containing the kernel calculations included by the value of complexity.
the kernel hyper-parameters. See details for hyper-parameter specification for each kerneltype.
the distance matrix between all time points s and t, i.e., |s - t|
the sign matrix of the time differences, i.e., sign(s - t)
size for band matrix approximation. See details.
integer value for the complexity of the kernel calculations desired:
0 includes C only
1 additionally includes Cprime, Cdoubleprime, dCdphi
2 or above additionally includes Ceigen1over, CeigenVec, Cinv, mphi, Kphi, Keigen1over, KeigenVec, Kinv, mphiLeftHalf, dCdphiCube
See details for their definitions.
must be one of matern, rbf, compact1, periodicMatern, generalMatern, rationalQuadratic. See details for the kernel formulae.
degrees of freedom, for generalMatern and rationalQuadratic kernels only. Default is df=2.01 for generalMatern and df=0.01 for rationalQuadratic.
a small value added to the diagonal elements of C and Kphi for numerical stability
The covariance formulae and the hyper-parameters phi for the supported kernels are as follows. Stationary kernels have \(C(s,t) = C(r)\) where \(r = |s-t|\) is the distance between the two time points. Generally, the hyper-parameter phi[1] controls the overall variance level while phi[2] controls the bandwidth.
maternThis is the simplified Matern covariance with df = 5/2:
$$C(r) = phi[1] * (1 + \sqrt 5 r/phi[2] + 5r^2/(3 phi[2]^2)) * \exp(-\sqrt 5 r/phi[2])$$
rbf$$C(r) = phi[1] * \exp(-r^2/(2 phi[2]^2))$$
compact1$$C(r) = phi[1] * \max(1-r/phi[2],0)^4 * (4r/phi[2]+1) $$
periodicMaternDefine \(r' = | \sin(r \pi/phi[3])*2 |\). Then the covariance is given by \(C(r')\) using the Matern formula.
generalMatern$$C(r) = phi[1] * 2^(1-df) / \Gamma(df) * ( \sqrt(2.0 * df) * r / phi[2] )^df * besselK( \sqrt(2.0 * df) * r / phi[2] , df)$$
where besselK is the modified Bessel function of the second kind.
rationalQuadratic$$C(r) = phi[1] * (1 + r^2/(2 df phi[2]^2))^(-df)$$
The kernel calculations available and their definitions are as follows:
The covariance matrix corresponding to the distance matrix rInput.
The cross-covariance matrix \(d C(s,t) / ds\).
The cross-covariance matrix \(d^2 C(s,t) / ds dt\).
A list with the matrices \(dC / dphi\) for each element of phi.
The reciprocals of the eigenvalues of C.
Matrix of eigenvectors of C.
The inverse of C.
The matrix Cprime * Cinv.
The matrix Cdoubleprime - Cprime * Kinv * t(Cprime).
The reciprocals of the eigenvalues of Kphi.
The inverse of Kphi.
The matrix Cprime * CeigenVec.
\(dC / dphi\) as a 3-D array, with the third dimension corresponding to the elements of phi.
If bandsize is a positive integer, additionally CinvBand, mphiBand, and KinvBand are provided in the return list, which are
band matrix approximations to Cinv, mphi, and Kinv with the specified bandsize.
foo <- outer(0:40, t(0:40), '-')[, 1, ]
r <- abs(foo)
signr <- -sign(foo)
calCov(c(0.2, 2), r, signr, bandsize = 20, kerneltype = "generalMatern", df = 2.01)
Run the code above in your browser using DataLab