Description Usage Arguments Value Examples
Compute all the w_i blocks of H
1 | compute_H_W(X, WHat, muHat, sigSqHat, K)
|
X |
Data |
WHat |
Loadings matrix |
K |
Prior covariance matrix |
H_w_i
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | set.seed(1)
d=10; k=3; n=10
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(1, 3)))
library(numDeriv)
library(Matrix)
Hw1.analytic = stpca:::compute_H_W(X, W, mu, sigSq, K)[[1]]
Hw1.numeric = Matrix(numDeriv::hessian(function(w) {
W_ = W
W_[,1] = w
-(log_likelihood(X, W_, mu, sigSq) + log_prior(K, W_, sigSq))
}, x=W[,1]))
stopifnot(all.equal(Hw1.analytic, Hw1.numeric))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.