[Bioc-devel] normalize.loess effizient method

Markus Schmidberger schmidb at ibe.med.uni-muenchen.de
Mon Jun 23 10:09:26 CEST 2008


Hello,

I parallelized the normalize loess function (see affyPara package). 
Thereby I found a memory inefficient implementation of normalize.loess.
The matrices fs and newdata are of the size of the complete intensity 
matrix and not necessary.  I removed this two matrices and the oldfs 
matrix. Attached the changed code.

Best
Markus


normalize.loess <- function(mat, subset=sample(1:(dim(mat)[1]), 
min(c(5000, nrow(mat)))),
        epsilon=10^-2, maxit=1, log.it=TRUE, verbose=TRUE, span=2/3,
        family.loess="symmetric"){
   
    J <- dim(mat)[2]
    II <- dim(mat)[1]
    if(log.it)
        mat <- log2(mat)
   
    change <- epsilon +1
    iter <- 0
    w <- c(0, rep(1,length(subset)), 0) ##this way we give 0 weight to the
    ##extremes added so that we can interpolate
   
    while(iter < maxit){
        iter <- iter + 1
        means <- matrix(0,II,J) ##contains temp of what we substract
       
        for (j in 1:(J-1)){
            for (k in (j+1):J){
                y <- mat[,j] - mat[,k]
                x <- (mat[,j] + mat[,k]) / 2
                index <- c(order(x)[1], subset, order(-x)[1])
                ##put endpoints in so we can interpolate
                xx <- x[index]
                yy <- y[index]
                aux <-loess(yy~xx, span=span, degree=1, weights=w, 
family=family.loess)
                aux <- predict(aux, data.frame(xx=x)) / J
                means[, j] <- means[, j] + aux
                means[, k] <- means[, k] - aux
                if (verbose)
                    cat("Done with",j,"vs",k," in iteration ",iter,"\n")
            }
        }
        mat <- mat - means
        change <- max(colMeans((means[subset,])^2))
       
        if(verbose)
            cat(iter, change,"\n")
   
    }
   
    if ((change > epsilon) & (maxit > 1))
        warning(paste("No convergence after", maxit, "iterations.\n"))
   
    if(log.it) {
        return(2^mat)
    } else
        return(mat)
}

-- 
Dipl.-Tech. Math. Markus Schmidberger

Ludwig-Maximilians-Universität München
IBE - Institut für medizinische Informationsverarbeitung,
Biometrie und Epidemiologie
Marchioninistr. 15, D-81377 Muenchen
URL: http://ibe.web.med.uni-muenchen.de 
Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de



More information about the Bioc-devel mailing list