#' Estimate average regret for a given J (MUST SET SEED)
#'
#' @param Jvals The differnt J values to try.
#' @param J_true The true value of J.
#' @param nsteps number of steps per simulation.
#' @param nsim The number of simulations for each value of J.
#' @param seed The seed to control the random outcome.
#'
#' @export
test_J <- function(Jvals,J_true,nsteps=2000,nsim=100,seed = 100){
cores <- parallel::detectCores()
wrap <- function(j){
sum <- 0
for (i in 1:nsim){
sim <- sim_rand_bandit(nsteps,2,j,J_true,rep(0.2,2))@trajectory$total_regret[nsteps]
sum <- sum + sim
}
return(sum/nsim)
}
RNGkind("L'Ecuyer-CMRG") #Needed for multithreaded seeds.
set.seed(seed)
out <- unlist(parallel::mclapply(Jvals,wrap))
names(out) <- as.character(Jvals)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.