## The function is currently defined as
function (prNCP, tol = 1e-04, maxit = 300, mu = 1)
{
print("Entered MLica")
X <- prNCP$X
x <- prNCP$x
pEx <- prNCP$pEx
pCorr <- prNCP$pCorr
ntp <- dim(X)[1]
ndim <- dim(X)[2]
ncp <- ncol(x)
Sest <- matrix(nrow = ntp, ncol = ncp)
B.old <- matrix(runif(ncp * ncp, 0, 1), nrow = ncp, ncol = ncp)
B.o <- B.old
icount <- 0
not.conv <- c(1, 2)
y <- matrix(nrow = ntp, ncol = ncp)
tmp <- matrix(nrow = ncp, ncol = ncp)
beta <- vector(length = ncp)
alpha <- vector(length = ncp)
while ((length(not.conv) > 0) && (icount < maxit)) {
print(c("Entering iteration loop ", icount))
Cy <- B.old %*% t(B.old)
svds <- eigen(Cy, symmetric = TRUE)
D <- diag(svds$values)
E <- svds$vectors
Dinv <- solve(D)
V <- E %*% sqrt(Dinv) %*% t(E)
B.old <- V %*% B.old
for (g in 1:ntp) {
y[g, ] <- B.old %*% x[g, ]
}
for (c in 1:ncp) {
beta[c] <- 2 * sum(y[, c] * tanh(y[, c]))/ntp
alpha[c] <- -1/(beta[c] - 2 + 2 * sum(tanh(y[, c]) *
tanh(y[, c]))/ntp)
for (c2 in 1:ncp) {
tmp[c, c2] <- -2 * sum(tanh(y[, c]) * y[, c2])/ntp
}
}
print("Checkpt1")
tmp <- diag(beta) + tmp
B <- B.old + mu * diag(alpha) %*% tmp %*% B.old
Dev <- abs(B - B.o)
AvDev <- sum(Dev)/(ncp * ncp)
print(c("AvDev=", AvDev))
not.conv <- vector()
not.conv <- as.vector(Dev[Dev > tol])
B.old <- B
B.o <- B
icount <- icount + 1
for (g in 1:ntp) {
Sest[g, ] <- B %*% x[g, ]
}
logL <- -2 * sum(log(cosh(Sest))) + ntp * log(abs(det(B)))
print("iterated logL")
print(logL)
}
Cy <- B %*% t(B)
svds <- eigen(Cy, symmetric = TRUE)
D <- diag(svds$values)
E <- svds$vectors
Dinv <- solve(D)
V <- E %*% sqrt(Dinv) %*% t(E)
B <- V %*% B
for (g in 1:ntp) {
Sest[g, ] <- B %*% x[g, ]
}
Aest <- t(pEx %*% sqrt(pCorr) %*% t(B))
if (length(not.conv) > 0) {
NotConv <- 1
}
else {
NotConv <- 0
}
logL <- -2 * sum(log(cosh(Sest))) + ntp * log(abs(det(B)))
return(list(A = Aest, B = B, S = Sest, X = X, ncp = dim(Sest)[2],
NC = NotConv, LL = logL))
}
Run the code above in your browser using DataLab