maxLikeICA: Maximum Likelihood Independent Component Analysis

Description Usage Arguments Examples

View source: R/maxLikeICA.R

Description

Symmetrical Estimate of Independent Components Using Maximum Likelihood.

Usage

1
maxLikeICA(x, g = g, max.iters = 12, init.w = diag(m), tol = 1e-04)

Arguments

x

A mixture set with variables in rows and observations in columns.

g

Current version only uses tanh()

max.iters

The maximum number of iterations. Default = 10.

init.w

The initial unmixing matrix. Default is identity.

tol

The tolerance for iteration differences...(?? come back here..). Default is 1e-4.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (x, g = g, max.iters = 12, init.w = diag(m), tol = 1e-04) 
{
    source("my_Whiten.R")
    g <- expression(tanh(y))
    norm_vec <- function(x) {
        sqrt(sum(x^2))
    }
    exp_xty <- function(x, y) {
        n <- ncol(x)
        m <- nrow(x)
        mat <- matrix(rep(0, m * m), nrow = m)
        for (i in 1:n) {
            mat <- mat + matrix(x[, i], nrow = m) %*% matrix(t(y)[i, 
                ], nrow = 1)
        }
        return(mat/n)
    }
    m <- nrow(x)
    n <- ncol(x)
    z <- my_Whiten(t(x))$z
    w <- init.w/apply(init.w, 1, norm_vec)
    iters <- max.iters
    dg <- D(g, "y")
    ws <- vector("list")
    ws[[1]] <- w
    distances <- vector()
    distances[1] <- 0
    i <- 1
    repeat {
        y <- w %*% z
        beta_i <- rowMeans(y * eval(g))
        alpha_i <- -1/(beta_i + rowMeans(eval(dg)))
        w <- w + diag(alpha_i) %*% (diag(beta_i) + exp_xty(eval(g), 
            y)) %*% w
        eigens <- eigen(w %*% t(w))
        E <- eigens$vectors
        D_invsqrt <- diag(1/sqrt(eigens$values))
        ww_inSqrt <- E %*% D_invsqrt %*% t(E)
        w <- ww_inSqrt %*% w
        ws[[i + 1]] <- w
        distances[i + 1] <- abs(norm(ws[[i]] - ws[[i + 1]]))
        if (i == iters | abs(distances[i] - distances[i + 1]) < 
            tol) {
            break
        }
        i <- i + 1
    }
    out <- list(ws = ws, W = w, S = w %*% z, iters = i, distances = distances)
  }

hanspeter6/icaPlay documentation built on May 2, 2020, 2:34 p.m.