R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("fastICA-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('fastICA') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "fastICA" > > ### * fastICA > > flush(stderr()); flush(stdout()) > > ### Name: fastICA > ### Title: FastICA algorithm > ### Aliases: fastICA > ### Keywords: multivariate > > ### ** Examples > > #--------------------------------------------------- > #Example 1: un-mixing two mixed independent uniforms > #--------------------------------------------------- > > S <- matrix(runif(10000), 5000, 2) > A <- matrix(c(1, 1, -1, 3), 2, 2, byrow = TRUE) > X <- S%*%A > > a <- fastICA(X, 2, alg.typ = "parallel", fun = "logcosh", alpha = 1, + method = "C", row.norm = FALSE, maxit = 200, + tol = 0.0001, verbose = TRUE) Centering Whitening Symmetric FastICA using logcosh approx. to neg-entropy function Iteration 1 tol=0.094395 Iteration 2 tol=0.015237 Iteration 3 tol=0.000002 > > par(mfrow = c(1, 3)) > plot(a$X, main = "Pre-processed data") > plot(a$X%*%a$K, main = "PCA components") > plot(a$S, main = "ICA components") > > #-------------------------------------------- > #Example 2: un-mixing two independent signals > #-------------------------------------------- > > S <- cbind(sin((1:1000)/20), rep((((1:200)-100)/100), 5)) > A <- matrix(c(0.291, 0.6557, -0.5439, 0.5572), 2, 2) > X <- S%*%A > > a <- fastICA(X, 2, alg.typ = "parallel", fun = "logcosh", alpha = 1, + method = "R", row.norm = FALSE, maxit = 200, + tol = 0.0001, verbose = TRUE) Centering Whitening Symmetric FastICA using logcosh approx. to neg-entropy function Iteration 1 tol = 0.05461492 Iteration 2 tol = 1.083779e-05 > > par(mfcol = c(2, 3)) > plot(1:1000, S[,1 ], type = "l", main = "Original Signals", + xlab = "", ylab = "") > plot(1:1000, S[,2 ], type = "l", xlab = "", ylab = "") > plot(1:1000, X[,1 ], type = "l", main = "Mixed Signals", + xlab = "", ylab = "") > plot(1:1000, X[,2 ], type = "l", xlab = "", ylab = "") > plot(1:1000, a$S[,1 ], type = "l", main = "ICA source estimates", + xlab = "", ylab = "") > plot(1:1000, a$S[, 2], type = "l", xlab = "", ylab = "") > > #----------------------------------------------------------- > #Example 3: using FastICA to perform projection pursuit on a > # mixture of bivariate normal distributions > #----------------------------------------------------------- > > if(require(MASS)){ + x <- mvrnorm(n = 1000, mu = c(0, 0), Sigma = matrix(c(10, 3, 3, 1), 2, 2)) + x1 <- mvrnorm(n = 1000, mu = c(-1, 2), Sigma = matrix(c(10, 3, 3, 1), 2, 2)) + X <- rbind(x, x1) + + a <- fastICA(X, 2, alg.typ = "deflation", fun = "logcosh", alpha = 1, + method = "R", row.norm = FALSE, maxit = 200, + tol = 0.0001, verbose = TRUE) + + par(mfrow = c(1, 3)) + plot(a$X, main = "Pre-processed data") + plot(a$X%*%a$K, main = "PCA components") + plot(a$S, main = "ICA components") + } Loading required package: MASS Centering Whitening Deflation FastICA using logcosh approx. to neg-entropy function Component 1 Iteration 1 tol = 0.707361 Iteration 2 tol = 0.004051272 Iteration 3 tol = 2.041869e-06 Component 2 Iteration 1 tol = 0 > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > ### *