## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse   = TRUE,
  comment    = "#>",
  fig.width  = 7,
  fig.height = 5,
  warning    = FALSE,
  message    = FALSE,
  eval       = FALSE
)

## ----plot-all, eval=FALSE-----------------------------------------------------
# library(dicepro)
# 
# p_all <- create_gamma_lambda_plot(hspaceTechniqueChoose = "all")
# p_all

## ----plot-restriction, eval=FALSE---------------------------------------------
# p_restr <- create_gamma_lambda_plot(hspaceTechniqueChoose = "restrictionEspace")
# p_restr

## ----simulate, eval=FALSE-----------------------------------------------------
# library(dicepro)
# set.seed(2101L)
# 
# sim <- simulation(
#   loi        = "gauss",
#   scenario   = "hierarchical",
#   nSample    = 30L,
#   nGenes     = 200L,
#   nCellsType = 10L,
#   sigma_bio  = 0.07,
#   sigma_tech = 0.07,
#   seed       = 2101L
# )
# 
# my_dataset <- list(
#   W = sim$W,
#   P = sim$p,
#   B = sim$B
# )
# 
# cat("W :", nrow(my_dataset$W), "genes x", ncol(my_dataset$W), "cell types\n")
# cat("P :", nrow(my_dataset$P), "samples x", ncol(my_dataset$P), "cell types\n")
# cat("B :", nrow(my_dataset$B), "genes x", ncol(my_dataset$B), "samples\n")
# cat("Row sums of P (range):", round(range(rowSums(my_dataset$P)), 4), "\n")

## ----run-all, eval=FALSE------------------------------------------------------
# results_all <- run_experiment(
#   dataset               = my_dataset,
#   W_prime               = 0,
#   bulkName              = "SimBulk",
#   refName               = "SimRef",
#   hp_max_evals          = 150L,
#   algo_select           = "random",
#   output_base_dir       = tempdir(),
#   hspaceTechniqueChoose = "all"
# )
# 
# cat("Completed trials:", nrow(results_all$trials), "\n")
# head(results_all$trials[, c("lambda_", "gamma", "p_prime", "loss", "constraint")])

## ----run-restriction, eval=FALSE----------------------------------------------
# results_restr <- run_experiment(
#   dataset               = my_dataset,
#   W_prime               = 0,
#   bulkName              = "SimBulk",
#   refName               = "SimRef",
#   hp_max_evals          = 150L,
#   algo_select           = "random",
#   output_base_dir       = tempdir(),
#   hspaceTechniqueChoose = "restrictionEspace"
# )
# 
# cat("Completed trials:", nrow(results_restr$trials), "\n")
# head(results_restr$trials[, c("lambda_", "gamma", "p_prime", "loss", "constraint")])

## ----compare-spaces, eval=FALSE, fig.height=6---------------------------------
# best_all   <- results_all$trials[which.min(results_all$trials$loss), ]
# best_restr <- results_restr$trials[which.min(results_restr$trials$loss), ]
# 
# cat("--- all ---\n")
# cat(sprintf("  lambda = %.3g  |  gamma = %.3g  |  loss = %.4f\n",
#             best_all$lambda_, best_all$gamma, best_all$loss))
# 
# cat("--- restrictionEspace ---\n")
# cat(sprintf("  lambda = %.3g  |  gamma = %.3g  |  loss = %.4f\n",
#             best_restr$lambda_, best_restr$gamma, best_restr$loss))
# 
# plot(
#   results_all$trials$gamma,
#   results_all$trials$lambda_,
#   log  = "xy",
#   pch  = 19, cex = 0.5,
#   col  = adjustcolor("steelblue", 0.4),
#   xlab = expression(gamma), ylab = expression(lambda),
#   main = "Sampled configurations: all (blue) vs restrictionEspace (orange)"
# )
# points(
#   results_restr$trials$gamma,
#   results_restr$trials$lambda_,
#   pch = 19, cex = 0.5,
#   col = adjustcolor("darkorange", 0.4)
# )
# legend("topleft",
#        legend = c("all", "restrictionEspace"),
#        col    = c("steelblue", "darkorange"),
#        pch    = 19, pt.cex = 1.2)

## ----session-info, eval=FALSE-------------------------------------------------
# sessionInfo()

