# NOT RUN {
if (require("LaplacesDemon")) {
# Generate sources from multivariate Laplace distribution
P <- 4; N <- 1000; D <- 4;
S <- array(NA, c(P, N, D))
for (i in 1:P) {
U <- array(rnorm(D * D), c(D, D))
Sigma <- crossprod(U)
S[i, , ] <- rmvl(N, rep(0, D), Sigma)
}
# 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")
# Plot all estimated sources
plot(res_G)
# Plot the source estimates for the first dataset only
plot(res_G, which.dataset = 1)
# Plot the source estimates for the second source only
plot(res_G, which.source = 2)
# Plot the source estimate of the second dataset and third source
plot(res_G, which.dataset = 2, which.source = 3, type = "p")
# Plot all source estimates with custom colors and labels
plot(res_G, col=c(rep(1, 4), rep(2, 4), rep(3, 4), rep(4, 4)),
xlabs = c("Subject 1", "Subject 2", "Subject 3", "Subject 4"),
ylabs = c("Channel 1", "Channel 2", "Channel 3", "Channel 4"))
}
# }
Run the code above in your browser using DataLab