# NOT RUN {
require(doParallel) # You can use a different package to set up the parallel backend
# Loading the data for this example
data(cell)
model <- BSLModel(fnSim = cell_sim, fnSum = cell_sum, simArgs = cell$sim_options,
sumArgs = cell$sum_options, theta0 = cell$start, fnLogPrior = cell_logPrior,
thetaNames = expression(P[m], P[p]))
true_cell <- c(0.35, 0.001)
# Performing BSL (reduce the number of iterations M if desired)
# Opening up the parallel pools using doParallel
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl)
resultCellBSL <- bsl(cell$data, n = 5000, M = 10000, model = model, covRandWalk = cell$cov,
parallel = TRUE, verbose = TRUE)
stopCluster(cl)
registerDoSEQ()
show(resultCellBSL)
summary(resultCellBSL)
plot(resultCellBSL, thetaTrue = true_cell, thin = 20)
# Performing uBSL (reduce the number of iterations M if desired)
# Opening up the parallel pools using doParallel
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl)
resultCelluBSL <- bsl(cell$data, n = 5000, M = 10000, model = model, covRandWalk = cell$cov,
method = 'uBSL', parallel = TRUE, verbose = TRUE)
stopCluster(cl)
registerDoSEQ()
show(resultCelluBSL)
summary(resultCelluBSL)
plot(resultCelluBSL, thetaTrue = true_cell, thin = 20)
# Performing tuning for BSLasso
ssy <- cell_sum(cell$data, cell$sum_options$Yinit)
lambda_all <- list(exp(seq(0.5,2.5,length.out=20)), exp(seq(0,2,length.out=20)),
exp(seq(-1,1,length.out=20)), exp(seq(-1,1,length.out=20)))
# Opening up the parallel pools using doParallel
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl)
set.seed(100)
sp_cell <- selectPenalty(ssy, n = c(500, 1000, 1500, 2000), lambda_all, theta = true_cell,
M = 100, sigma = 1.5, model = model, method = 'BSL', shrinkage = 'glasso',
parallelSim = TRUE, parallelMain = FALSE)
stopCluster(cl)
registerDoSEQ()
sp_cell
plot(sp_cell)
# Performing BSLasso with a fixed penalty (reduce the number of iterations M if desired)
# Opening up the parallel pools using doParallel
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl)
resultCellBSLasso <- bsl(cell$data, n = 1500, M = 10000, theta0 = cell$start,
covRandWalk = cell$cov, fnSim = cell_sim, fnSum = cell_sum,
shrinkage = 'glasso', penalty = 1.3, fnPrior = cell_prior,
simArgs = cell$sim_options, sumArgs = cell$sum_options,
parallel = TRUE, parallelArgs = list(.packages = 'BSL'),
thetaNames = expression(P[m], P[p]), verbose = TRUE)
stopCluster(cl)
registerDoSEQ()
show(resultCellBSLasso)
summary(resultCellBSLasso)
plot(resultCellBSLasso, thetaTrue = true_cell, thin = 20)
# Performing semiBSL (reduce the number of iterations M if desired)
# Opening up the parallel pools using doParallel
cl <- makeCluster(detectCores() - 1)
registerDoParallel(cl)
resultCellSemiBSL <- bsl(cell$data, n = 5000, M = 10000, theta0 = cell$start,
covRandWalk = cell$cov, fnSim = cell_sim, fnSum = cell_sum,
method = 'semiBSL', fnPrior = cell_prior,
simArgs = cell$sim_options, sumArgs = cell$sum_options,
parallel = TRUE, parallelArgs = list(.packages = 'BSL'),
thetaNames = expression(P[m], P[p]), verbose = TRUE)
stopCluster(cl)
registerDoSEQ()
show(resultCellSemiBSL)
summary(resultCellSemiBSL)
plot(resultCellSemiBSL, thetaTrue = true_cell, thin = 20)
# Plotting the results together for comparison
# plot using the R default plot function
par(mar = c(5, 4, 1, 2), oma = c(0, 1, 2, 0))
combinePlotsBSL(list(resultCellBSL, resultCelluBSL, resultCellBSLasso, resultCellSemiBSL),
which = 1, thetaTrue = true_cell, thin = 20, label = c('bsl', 'ubsl', 'bslasso', 'semiBSL'),
col = 1:4, lty = 1:4, lwd = 1)
mtext('Approximate Univariate Posteriors', outer = TRUE, cex = 1.5)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab