cov.SE.d: Squared exponential covariance function derivatives wrt...

Description Usage Examples

View source: R/covariance-functions.R

Description

Squared exponential covariance function derivatives wrt hyperparameters

Usage

1
cov.SE.d(X, X2, beta, D = NA, ...)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
point1 = matrix(rnorm(1), ncol=1)
point2 = matrix(rnorm(1), ncol=1)
beta   = rnorm(2) # Logarithms of variance and length scale

Ks.1point = cov.SE.d(point1, beta=beta)

# Derivative wrt variance at zero distance should always be exp(beta[1])
stopifnot(all.equal(Ks.1point[[1]][1,1], exp(beta[1])))

# Derivative wrt lengthscale at zero distance should always be 0
stopifnot(all.equal(Ks.1point[[2]][1,1], 0))

# Identical tests with numerical gradient
library(numDeriv)
Ks.1point.num = grad(function(beta_) {
  cov.SE(point1, beta=beta_)[1,1]
}, x=beta)
stopifnot(all.equal(Ks.1point.num[1], exp(beta[1])))
stopifnot(all.equal(Ks.1point.num[2], 0))

Ks.2points = cov.SE.d(point1, point2, beta=beta)
Ks.2points.num = grad(function(beta_) {
  as.numeric(cov.SE(point1, point2, beta=beta_))
}, x=beta)

# Check numerical gradient equals analytic gradient
stopifnot(all.equal(as.numeric(Ks.2points[[1]]), Ks.2points.num[1]))
stopifnot(all.equal(as.numeric(Ks.2points[[2]]), Ks.2points.num[2]))

JimSkinner/spca documentation built on Aug. 19, 2018, 7 a.m.