Description Usage Arguments Value Examples
Calculate the log likelihood for StPCA with given parameters
1 | log_likelihood(X, W, mu, sigSq)
|
X |
Data |
log likelihood (numeric)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | d = 50
k = 5
n = 15
set.seed(1)
X = matrix(rnorm(n*d), nrow=n, ncol=d)
mu = colMeans(X)
Xc = sweep(X, 2, mu, '-')
covar.svd = svd(Xc/sqrt(n), nu=0, nv=k)
covar.eigval = covar.svd$d^2
sigSq = sum(covar.eigval[-(1:k)])/(d-k)
W = covar.svd$v %*% diag(sqrt(covar.eigval[1:k] - sigSq), ncol=k, nrow=k)
R = svd(matrix(rnorm(k*k), ncol=k, nrow=k))$u # Random orthonormal matrix
# The likelihood is invariant to multiplying by an orthonormal matrix.
l1 = log_likelihood(X, W, mu, sigSq)
l2 = log_likelihood(X, W%*%R, mu, sigSq)
stopifnot(all.equal(l1, l2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.