Skip to content

Commit

Permalink
fix: deal with 0 only vars in lambda_seq & constrain lambda_max to ac…
Browse files Browse the repository at this point in the history
…celerate convergence
  • Loading branch information
gufengzhou committed Feb 24, 2022
1 parent eff2904 commit d748aa7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion R/R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ robyn_mmm <- function(InputCollect,
y = dt_mod$dep_var,
seq_len = 100, lambda_min_ratio)
lambda_min_ratio
lambda_max <- max(lambdas)
lambda_max <- max(lambdas) * 0.1
lambda_min <- lambda_max * lambda_min_ratio

################################################
Expand Down Expand Up @@ -1333,6 +1333,8 @@ model_refit <- function(x_train, y_train, lambda, lower.limits, upper.limits, in
lambda_seq <- function(x, y, seq_len = 100, lambda_min_ratio = 0.0001) {
mysd <- function(y) sqrt(sum((y - mean(y))^2) / length(y))
sx <- scale(x, scale = apply(x, 2, mysd))
check_nan <- apply(sx, 2, function(sxj) all(is.nan(sxj)))
sx <- mapply(function(sxj, v) return(if(v) rep(0, length(sxj)) else sxj), sxj = as.data.frame(sx), v = check_nan)
sx <- as.matrix(sx, ncol = ncol(x), nrow = nrow(x))
# sy <- as.vector(scale(y, scale=mysd(y)))
sy <- y
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ OutputModels <- robyn_run(
#, cores = NULL # default
#, add_penalty_factor = FALSE # Untested feature. Use with caution.
, iterations = 2000 # recommended for the dummy dataset
, trials = 5 # recommended for the dummy dataset
, trials = 1 # recommended for the dummy dataset
, outputs = FALSE # outputs = FALSE disables direct model output
)
print(OutputModels)
Expand Down

0 comments on commit d748aa7

Please sign in to comment.