Skip to contents

Step 2

Estimate Methods

With minimal configuration, users can estimate optimal parameters using four distinct methods. In the following code snippets, I only highlight the arguments that vary by estimation method. Unless explicitly noted, other arguments can be duplicated from the above example.

# How to use MLE as estimate method
recovery.MLE <- multiRL::rcv_d(
  estimate = "MLE",
  control = list(
    core = 10, sample = 100, iter = 100
  ),
  ...
)
# How to use MAP as estimate method
recovery.MAP <- multiRL::rcv_d(
  estimate = "MAP",
  control = list(
    core = 10, sample = 100, iter = 100,
    diff = 0.001, patience = 10
  ),
  ...
)
# How to use ABC as estimate method
recovery.ABC <- multiRL::rcv_d(
  estimate = "ABC",
  control = list(
    core = 10, sample = 100, train = 1000,
    tol = 0.1
  ),
  ...
)

# How to use RNN as estimate method
reticulate::use_condaenv(condaenv = "your_tensorflow_env_name", required = TRUE)

recovery.RNN <- multiRL::rcv_d(
  estimate = "RNN",
  control = list(
    core = 1, sample = 100, train = 1000,
    layer = "GRU", units = 128, batch_size = 10, epochs = 100
  ),
  ...
)

Note
All of the following figures were generated using multiRL::rpl_e()

Demo

MLE

recovery.MLE <- multiRL::rcv_d(
  estimate = "MLE",

  data = data,
  behrule = behrule,
  colnames = colnames,

  models = list(multiRL::TD, multiRL::RSTD, multiRL::Utility),
  priors = list(
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alphaN = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      alphaP = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)},
      gamma = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}
    )
  ),
  settings = list(name = c("TD", "RSTD", "Utility")),
  
  algorithm = "NLOPT_GN_MLSL",
  lowers = list(c(0, 0), c(0, 0, 0), c(0, 0, 0)),
  uppers = list(c(1, 10), c(1, 1, 10), c(1, 10, 1)),
  control = list(core = 10, sample = 100, iter = 100)
)

save(recovery.MLE, file = "./recovery.MLE.Rdata")

TD_alphaTD_beta

RSTD_alphaNRSTD_alphaPRSTD_beta

Utility_alphaUtility_betaUtility_gamma

Confusion_MatrixInversion_Matrix

MAP

recovery.MAP <- multiRL::rcv_d(
  estimate = "MAP",

  data = data,
  behrule = behrule,
  colnames = colnames,

  models = list(multiRL::TD, multiRL::RSTD, multiRL::Utility),
  priors = list(
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alphaN = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      alphaP = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)},
      gamma = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}
    )
  ),
  settings = list(name = c("TD", "RSTD", "Utility")),
  
  algorithm = "NLOPT_GN_MLSL",
  lowers = list(c(0, 0), c(0, 0, 0), c(0, 0, 0)),
  uppers = list(c(1, 10), c(1, 1, 10), c(1, 10, 1)),
  control = list(
    core = 10, sample = 100, iter = c(100, 1),
    diff = 0.1, patience = 10
  )
)

save(recovery.MAP, file = "./recovery.MAP.Rdata")

TD_alphaTD_beta

RSTD_alphaNRSTD_alphaPRSTD_beta

Utility_alphaUtility_betaUtility_gamma

Confusion_MatrixInversion_Matrix

ABC

recovery.ABC <- multiRL::rcv_d(
  estimate = "ABC",

  data = data,
  behrule = behrule,
  colnames = colnames,

  models = list(multiRL::TD, multiRL::RSTD, multiRL::Utility),
  priors = list(
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alphaN = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      alphaP = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)},
      gamma = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}
    )
  ),
  settings = list(name = c("TD", "RSTD", "Utility")),
  
  lowers = list(c(0, 0), c(0, 0, 0), c(0, 0, 0)),
  uppers = list(c(1, 10), c(1, 1, 10), c(1, 10, 1)),
  control = list(
    core = 10, sample = 100, train = 1000,
    tol = 0.1
  )
)

save(recovery.ABC, file = "./recovery.ABC.Rdata")

TD_alphaTD_beta

RSTD_alphaNRSTD_alphaPRSTD_beta

Utility_alphaUtility_betaUtility_gamma

Confusion_MatrixInversion_Matrix

RNN

reticulate::use_condaenv(condaenv = "tf-gpu", required = TRUE)

#> Show in New Window
#> -------------------------------------------------------------------
#> reticulate::use_condaenv(condaenv = "tensorflow", required = TRUE)
#> -------------------------------------------------------------------
#> 
#> Please confirm you have loaded TensorFlow into R (enter 1 or 2). 
#> 
#> 1: Yes, it is loaded
#> 2: No, it is not loaded

recovery.RNN <- multiRL::rcv_d(
  estimate = "RNN",

  data = data,
  behrule = behrule,
  colnames = colnames,

  models = list(multiRL::TD, multiRL::RSTD, multiRL::Utility),
  priors = list(
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alphaN = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      alphaP = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)}
    ),
    list(
      alpha = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}, 
      beta = function(x) {stats::rexp(n = 1, rate = 1)},
      gamma = function(x) {stats::rbeta(n = 1, shape1 = 2, shape2 = 2)}
    )
  ),
  settings = list(name = c("TD", "RSTD", "Utility")),
  
  lowers = list(c(0, 0), c(0, 0, 0), c(0, 0, 0)),
  uppers = list(c(1, 10), c(1, 1, 10), c(1, 10, 1)),
  control = list(
    core = 1, sample = 100, train = 1000,
    layer = "GRU", units = 128, batch_size = 10, epochs = 100
  ),
)

save(recovery.RNN, file = "./recovery.RNN.Rdata")

TD_alphaTD_beta

RSTD_alphaNRSTD_alphaPRSTD_beta

Utility_alphaUtility_betaUtility_gamma

Confusion_MatrixInversion_Matrix