R/test_J.R

Defines functions test_J

Documented in test_J

#' 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)
}
dfcorbin/npbanditC documentation built on March 23, 2020, 5:25 a.m.