## Not run:
# library(golubEsets)
# data(Golub_Merge)
# smallG <- Golub_Merge[200:250,]
#
# # Evaluation on one node
#
# lk1 <- xval(smallG, "ALL.AML", knnB, xvalMethod="LOO", group=as.integer(0))
# table(lk1,smallG$ALL.AML)
#
# # Evaluation on several nodes -- a cluster programmer might write the following...
#
# library(snow)
# setOldClass("spawnedMPIcluster")
#
# setMethod("xvalLoop", signature( cluster = "spawnedMPIcluster"),
# ## use the function returned below to evalutae
# ## the central cross-validation loop in xval
# 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)
# }
# function(X, FUN, ...) { # this gets returned to xval
# ## send all visible variables from the parent (i.e., xval) frame
# clusterExportEnv( cluster, parent.frame(1) )
# parLapply( cluster, X, FUN, ... )
# }
# })
#
# # ... and use the cluster like this...
#
# cl <- makeCluster(2, "MPI")
# clusterEvalQ(cl, library(MLInterfaces))
#
# lk1 <- xval(smallG, "ALL.AML", knnB, xvalMethod="LOO", group=as.integer(0), cluster = cl)
# table(lk1,smallG$ALL.AML)
# ## End(Not run)
Run the code above in your browser using DataCamp Workspace