# NOT RUN {
if (require("LaplacesDemon")) {
# Generate sources from multivariate Laplace distribution
P <- 4; N <- 1000; D <- 4;
S <- array(NA, c(P, N, D))
sigmas <- list()
for (i in 1:P) {
U <- array(rnorm(D * D), c(D, D))
sigmas[[i]] <- crossprod(U)
S[i, , ] <- rmvl(N, rep(0, D), sigmas[[i]])
}
# Generate mixing matrices from standard normal distribution
A <- array(rnorm(P * P * D), c(P, P, D))
# Generate mixtures
X <- array(NaN, c(P, N, D))
for (d in 1:D) {
X[, , d] <- A[, , d] %*% S[, , d]
}
# Estimate sources and unmixing matrices
res_G <- NewtonIVA(X, source_density = "gaussian")
# Generate new observarions
N_new <- 10
S_new <- array(NA, c(P, N_new, D))
for (i in 1:P) {
S_new[i, , ] <- rmvl(N_new, rep(0, D), sigmas[[i]])
}
X_new <- array(NaN, c(P, N_new, D))
for (d in 1:D) {
X_new[, , d] <- A[, , d] %*% S_new[, , d]
}
# Get source estimates for the new observations
pred <- predict(res_G, X_new)
# Get source estimates for only the second dataset
pred2 <- predict(res_G, X_new[, , 2], which.dataset = 2)
}
# }
Run the code above in your browser using DataLab