Commit 6508ec1b authored by Marco De Lucia's avatar Marco De Lucia
Browse files

changed parallelization backend to fix bug in demo-eq-surr-RF.R

parent 391471d5
......@@ -83,6 +83,12 @@ baleq <- list(Calcite=c(C=1, Ca=1), Dolomite=c(C=2, Ca=1, Mg=1))
balance <- CheckBalance(baleq, sam$design, sam$result)
## we import the caret library
library(caret)
## we register the parallelization backend
doParallel::registerDoParallel(4)
set.seed(95014)
fitControl <- trainControl(method = "none",
allowParallel = TRUE,
......@@ -92,14 +98,24 @@ fitControl <- trainControl(method = "none",
predictionBounds=rep(TRUE,2))
## this takes around 8 minutes using 4 cores
## modk <- parallel::mclapply(colnames(sam$result), function (x)
## return(train(x=sam$design, y=sam$result[,x],trControl = fitControl, ##tuneGrid = tg,
## method="parRF")), mc.cores=8)
traintime <- system.time({
mods <- parallel::mclapply(colnames(sam$result), function (x)
return(train(x=sam$design, y=sam$result[,x],trControl = fitControl,
method="parRF")), mc.cores=7)
names(mods) <- colnames(sam$result)
mods <- foreach(i=colnames(sam$result)) %dopar% caret::train(x=sam$design, y=sam$result[,i], trControl = fitControl, method="parRF")
})
names(mods) <- colnames(sam$result)
## ## this takes around 8 minutes using 4 cores
## traintime <- system.time({
## mods <- parallel::mclapply(colnames(sam$result), function (x)
## return(train(x=sam$design, y=sam$result[,x],trControl = fitControl,
## method="parRF")), mc.cores=7)
## names(mods) <- colnames(sam$result)
## })
PlotModsInSample(mods, sam$result, sam$design)
saveRDS(mods, "models_equilibrium_RF.rds")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment