Skip to content

How to Use

Colby Ford edited this page Aug 15, 2018 · 1 revision

How to use the parEBEN package

Load in libraries

library(parEBEN)
library(EBEN)

Initialize parallelization

Using doParallel

library(doParallel)
cl <- makeCluster(8)
registerDoParallel(cl)

Using doMPI

library(doMPI)
if (!identical(getDoParName(), 'doMPI')) {
  cl <- startMPIcluster(count=256,verbose=TRUE)
  registerDoMPI(cl)
}

Using doSNOW

library(doSNOW)
cl <- makeMPIcluster(256)
registerDoSNOW(cl)

Create small sample matrix for testing

data(BASIS)
data(y)
n = 50
k = 100
BASIS = BASIS[1:n,1:k]
y  = y[1:n]

Find optimal hyperparameter values using CrossValidate

parEBENcv <- CrossValidate(BASIS,
                           y,
                           nFolds = 3,
                           Epis = "no",
                           prior = "gaussian",
                           search = "global")

Use the optimal values in the EBEN model

EBENoutput <- EBelasticNet.Gaussian(BASIS,
                                    y,
                                    lambda = parEBENcv$lambda.optimal,
                                    alpha = parEBENcv$alpha.optimal,
                                    Epis = "no",
                                    verbose = 1)