compute_H_W: Compute all the w_i blocks of H

Description Usage Arguments Value Examples

View source: R/H.R

Description

Compute all the w_i blocks of H

Usage

1
compute_H_W(X, WHat, muHat, sigSqHat, K)

Arguments

X

Data

WHat

Loadings matrix

K

Prior covariance matrix

Value

H_w_i

Examples

 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))

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