Description Usage Arguments Value Examples
Compute all the blocks of H.
1 | compute_H(X, WHat, muHat, sigSqHat, K)
|
X |
Data |
WHat |
Loadings matrix |
K |
Prior covariance matrix |
H
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | set.seed(1)
d=10; k=3; n=1000
X = matrix(rnorm(n*d), ncol=d)
W = matrix(rnorm(d*k), ncol=k)
mu = rnorm(d)
sigSq = rnorm(1)^2
K = cov.SE(matrix(1:10, ncol=1), beta=log(c(2, 3)))
library(numDeriv)
library(Matrix)
#Test that the analytic hessian for mu & sigSq matches numerical Hessian.
H.analytic = stpca:::compute_H(X, W, mu, sigSq, K)
HsigSq.numeric = Matrix(numDeriv::hessian(function(sigSq_) {
-(log_likelihood(X, W, mu, sigSq_) + log_prior(K, W, sigSq))
}, x=sigSq))
stopifnot(all.equal(H.analytic$sigSq, HsigSq.numeric,
tolerance=1e-8))
Hmu.numeric = numDeriv::hessian(function(mu_) {
-log_likelihood(X, W, mu_, sigSq)
}, x=mu)
stopifnot(isTRUE(all.equal(unname(as.matrix(H.analytic$mu)),
Hmu.numeric, tolerance=1e-6)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.