################################################### ### chunk number 1: ################################################### options(width=60) ################################################### ### chunk number 2: init ################################################### library(MLInterfaces) library(golubEsets) smallG <- Golub_Merge[200:250,] ################################################### ### chunk number 3: xval ################################################### lk1 <- MLearn(ALL.AML~., smallG, knnI(k=1), xvalSpec("LOO")) confuMat(lk1) ################################################### ### chunk number 4: clusterinit eval=FALSE ################################################### ## library(MLInterfaces) ## library(golubEsets) ## smallG <- Golub_Merge[200:250,] ################################################### ### chunk number 5: clusterstart eval=FALSE ################################################### ## library(snow) ## cl <- makeCluster(8, "MPI") ## clusterEvalQ(cl, library(MLInterfaces)) ################################################### ### chunk number 6: clustercalc eval=FALSE ################################################### ## lk1 <- xval(smallG, "ALL.AML", knnB, xvalMethod="LOO", ## group=as.integer(0), cluster = cl) ## table(lk1,smallG$ALL.AML) ################################################### ### chunk number 7: eval=FALSE ################################################### ## setMethod("xvalLoop", ## signature( cluster = "ANY" ), ## function( cluster, ... ) lapply ) ################################################### ### chunk number 8: eval=FALSE ################################################### ## setOldClass( "spawnedMPIcluster" ) ## setMethod("xvalLoop", ## signature( cluster = "spawnedMPIcluster" ), ## function( cluster, ... ) parLapply ) ################################################### ### chunk number 9: eval=FALSE ################################################### ## setOldClass( "spawnedMPIcluster" ) ## setMethod("xvalLoop", ## signature( cluster = "spawnedMPIcluster" ), ## function( cluster, ... ) { ## relapply <- function(X, FUN, ...) { ## parLapply( cluster, X, FUN, ... ) ## } ## relapply ## }) ################################################### ### chunk number 10: eval=FALSE ################################################### ## setMethod("xvalLoop", signature( cluster = "spawnedMPIcluster"), ## function( cluster, ... ) { ## clusterExportEnv <- function (cl, env = .GlobalEnv) ## { ## unpackEnv <- function(env) { ## for ( name in ls(env) ) assign(name, get(name, env), .GlobalEnv ) ## NULL ## } ## clusterCall(cl, unpackEnv, env) ## } ## relapply <- function(X, FUN, ...) { ## ## send all visible variables from the parent (i.e., xval) frame ## clusterExportEnv( cluster, parent.frame(1) ) ## parLapply( cluster, X, FUN, ... ) ## } ## relapply ## }) ################################################### ### chunk number 11: ################################################### res <- c(20.04,11.34, 9.23, 8.20, 7.87) plot(res,ylab="Time (seconds)", xlab="Nodes", ylim=c(0,max(res))) ################################################### ### chunk number 12: eval=FALSE ################################################### ## harness <- function( nodes, reps, data ) { ## if ( nodes > 1) { ## cl <- makeCluster(nodes, "MPI") ## clusterEvalQ(cl, library(MLInterfaces)) ## } else cl <- NULL ## func <- function(x) ## res <- xval(data, "ALL.AML", knnB, xvalMethod = "LOO", 0:0, cluster = cl ) ## func() # warm-up ## tm <- system.time( sapply( 1:reps, func ) )[3] ## if (nodes > 1) stopCluster(cl) ## tm ## } ## res <- sapply( 1:5, harness, 10, smallG ) ################################################### ### chunk number 13: ################################################### x <- 1:10 for (i in 1:10) x[i] <- i**2 x # x has been modified by the for loop x <- 1:10 res <- lapply(1:10, function(i) x[i] <- i**2) x # copy of x in lapply modified, not the global x