Skip to content

Commit

Permalink
feat: new seed parameter forced into py for reproducible results
Browse files Browse the repository at this point in the history
  • Loading branch information
laresbernardo committed Oct 26, 2021
1 parent 61c9e75 commit a7c22c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 7 additions & 1 deletion R/R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -830,16 +830,22 @@ robyn_run <- function(InputCollect,
#' Defaults to 100.
#' @param lambda_fixed Boolean. \code{lambda_fixed = TRUE} when inputting
#' old model results.
#' @param seed Integer. For reproducible results when running nevergrad.
#' @export
robyn_mmm <- function(hyper_collect,
InputCollect,
iterations = InputCollect$iterations,
lambda.n = 100,
lambda_control = 1,
lambda_fixed = NULL,
refresh = FALSE) {
refresh = FALSE,
seed = 123L) {
if (reticulate::py_module_available("nevergrad")) {
ng <- reticulate::import("nevergrad", delay_load = TRUE)
if (is.integer(seed)) {
np <- reticulate::import("numpy", delay_load = FALSE)
np$random$seed(seed)
}
} else {
stop("You must have nevergrad python library installed.")
}
Expand Down
5 changes: 4 additions & 1 deletion R/man/robyn_mmm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions demo/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ options(future.fork.enable = TRUE)
# virtualenv_create("r-reticulate")
# use_virtualenv("r-reticulate", required = TRUE)
# py_install("nevergrad", pip = TRUE)
# py_config() # Check your python version and configurations
## In case nevergrad still can't be installed,
# Sys.setenv(RETICULATE_PYTHON = "~/.virtualenvs/r-reticulate/bin/python")
# Reset your R session and re-install Nevergrad with option 1

## Option 2: nevergrad installation via conda
# conda_create("r-reticulate", "Python 3.9") # Only works with <= Python 3.9 sofar
# use_condaenv("r-reticulate")
# conda_install("r-reticulate", "nevergrad", pip=TRUE)

# py_config() # Check your python version and configurations
## In case nevergrad still can't be installed,
## please locate your python file and run this line with your path:
# use_python("~/Library/r-miniconda/envs/r-reticulate/bin/python3.9")
# Alternatively, force Python path for reticulate with this:
# Sys.setenv(RETICULATE_PYTHON = "~/Library/r-miniconda/envs/r-reticulate/bin/python3.9")
# Finally, re-install Nevergrad with option 1 or 2 above
# Check this issue for more ideas https://github.com/facebookexperimental/Robyn/issues/189
# Finally, reset your R session and re-install Nevergrad with option 2

# Check this issue for more ideas to debug your reticulate/nevergrad issues:
# https://github.com/facebookexperimental/Robyn/issues/189

################################################################
#### Step 1: load data
Expand Down Expand Up @@ -321,7 +327,7 @@ OutputCollect <- robyn_run(
## your business reality

OutputCollect$allSolutions # get all model IDs in result
select_model <- "2_8_1" # select one from above
select_model <- "1_4_2" # select one from above
robyn_save(robyn_object = robyn_object # model object location and name
, select_model = select_model # selected model ID
, InputCollect = InputCollect # all model input
Expand Down

0 comments on commit a7c22c6

Please sign in to comment.