4949# ' In other words, given the same DECOMP.RSSD score, a model with 50\% 0-coef
5050# ' variables will get penalized by DECOMP.RSSD * 1.5 (larger error), while
5151# ' another model with no 0-coef variables gets un-penalized with DECOMP.RSSD * 1.
52+ # ' @param objective_weights Numeric. Default to NULL that gives equal weights
53+ # ' to all objective functions. Set c(2, 1) to give double weight to the 1st.
54+ # ' This is an experimental feature. There's no research on optimal weight
55+ # ' setting. Subjective weights might strongly bias modelling result.
5256# ' @param seed Integer. For reproducible results when running nevergrad.
5357# ' @param outputs Boolean. Process results with \code{robyn_outputs()}?
5458# ' @param lambda_control Deprecated in v3.6.0.
@@ -81,6 +85,7 @@ robyn_run <- function(InputCollect = NULL,
8185 trials = 5 ,
8286 iterations = 2000 ,
8387 rssd_zero_penalty = TRUE ,
88+ objective_weights = NULL ,
8489 nevergrad_algo = " TwoPointsDE" ,
8590 intercept = TRUE ,
8691 intercept_sign = " non_negative" ,
@@ -135,6 +140,7 @@ robyn_run <- function(InputCollect = NULL,
135140 check_run_inputs(cores , iterations , trials , intercept_sign , nevergrad_algo )
136141 check_iteration(InputCollect $ calibration_input , iterations , trials , hyps_fixed , refresh )
137142 init_msgs_run(InputCollect , refresh , lambda_control = NULL , quiet )
143+ objective_weights <- check_obj_weight(InputCollect $ calibration_input , objective_weights , refresh )
138144
139145 # ####################################
140146 # ### Prepare hyper-parameters
@@ -160,6 +166,7 @@ robyn_run <- function(InputCollect = NULL,
160166 ts_validation = ts_validation ,
161167 add_penalty_factor = add_penalty_factor ,
162168 rssd_zero_penalty = rssd_zero_penalty ,
169+ objective_weights = objective_weights ,
163170 refresh , seed , quiet
164171 )
165172
@@ -290,6 +297,7 @@ robyn_train <- function(InputCollect, hyper_collect,
290297 dt_hyper_fixed = NULL ,
291298 ts_validation = TRUE ,
292299 add_penalty_factor = FALSE ,
300+ objective_weights = NULL ,
293301 rssd_zero_penalty = TRUE ,
294302 refresh = FALSE , seed = 123 ,
295303 quiet = FALSE ) {
@@ -309,6 +317,7 @@ robyn_train <- function(InputCollect, hyper_collect,
309317 ts_validation = ts_validation ,
310318 add_penalty_factor = add_penalty_factor ,
311319 rssd_zero_penalty = rssd_zero_penalty ,
320+ objective_weights = objective_weights ,
312321 seed = seed ,
313322 quiet = quiet
314323 )
@@ -345,6 +354,7 @@ robyn_train <- function(InputCollect, hyper_collect,
345354 ts_validation = ts_validation ,
346355 add_penalty_factor = add_penalty_factor ,
347356 rssd_zero_penalty = rssd_zero_penalty ,
357+ objective_weights = objective_weights ,
348358 refresh = refresh ,
349359 trial = ngt ,
350360 seed = seed + ngt ,
@@ -401,6 +411,7 @@ robyn_mmm <- function(InputCollect,
401411 intercept_sign ,
402412 ts_validation = TRUE ,
403413 add_penalty_factor = FALSE ,
414+ objective_weights = NULL ,
404415 dt_hyper_fixed = NULL ,
405416 # lambda_fixed = NULL,
406417 rssd_zero_penalty = TRUE ,
@@ -529,11 +540,24 @@ robyn_mmm <- function(InputCollect,
529540 my_tuple <- tuple(hyper_count )
530541 instrumentation <- ng $ p $ Array(shape = my_tuple , lower = 0 , upper = 1 )
531542 optimizer <- ng $ optimizers $ registry [optimizer_name ](instrumentation , budget = iterTotal , num_workers = cores )
543+
532544 # Set multi-objective dimensions for objective functions (errors)
533545 if (is.null(calibration_input )) {
534546 optimizer $ tell(ng $ p $ MultiobjectiveReference(), tuple(1 , 1 ))
547+ if (is.null(objective_weights )) {
548+ objective_weights <- tuple(1 , 1 )
549+ } else {
550+ objective_weights <- tuple(objective_weights [1 ], objective_weights [2 ])
551+ }
552+ optimizer $ set_objective_weights(objective_weights )
535553 } else {
536554 optimizer $ tell(ng $ p $ MultiobjectiveReference(), tuple(1 , 1 , 1 ))
555+ if (is.null(objective_weights )) {
556+ objective_weights <- tuple(1 , 1 , 1 )
557+ } else {
558+ objective_weights <- tuple(objective_weights [1 ], objective_weights [2 ], objective_weights [3 ])
559+ }
560+ optimizer $ set_objective_weights(objective_weights )
537561 }
538562 }
539563
0 commit comments