Skip to content

Commit

Permalink
speedup single var cond
Browse files Browse the repository at this point in the history
  • Loading branch information
jkapar committed Feb 21, 2024
1 parent ff122ce commit 9af0a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/forge.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ forge <- function(
index_start <- (step_-1)*stepsize_foreach + 1
index_end <- min(step_*stepsize_foreach, nrow(condition))
condition_part <- condition[index_start:index_end,]
cparams <- cforde(params, condition_part, condition_row_mode, 200)
cparams <- cforde(params, condition_part, condition_row_mode, stepsize)
} else {
cparams <- NULL
}
Expand Down
17 changes: 7 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ cforde <- function(params, condition, row_mode = c("separate", "or"), stepsize =
cnt_conds_compact <- copy(cnt_conds)
cnt_conds_compact[!is.na(val), `:=`(min = val, max = val)][,val := NULL]

cnt_relevant <- cnt[,.(min = .(min), max = .(max)),by = .(variable)]
cnt_relevant <- cnt_conds_compact[cnt_relevant,on = .(variable)]
cnt_relevant <- cnt[,.(min = .(min), max = .(max)),by = variable]
cnt_relevant <- cnt_conds_compact[cnt_relevant,on = .(variable), nomatch = NULL]

if (nrow(cat_conds) != 0) {
cnt_relevant <- cnt_relevant[relevant_leaves_cat_list, on = .(c_idx)]
Expand Down Expand Up @@ -499,14 +499,11 @@ cforde <- function(params, condition, row_mode = c("separate", "or"), stepsize =

if(nrow(cvg_new) > 0) {
cvg_new <- merge(cvg_new, forest_new[,.(f_idx, cvg_arf)], sort = F)
cvg_new[, `:=` (cvg = {
if (any(cvg_factor == 0)) {
-Inf
} else {
sum(log(c(cvg_arf[1], cvg_factor)))
}
})
, by = f_idx]
if (cvg_new[,max(f_idx) == .N]) {
cvg_new[, cvg := log(cvg_arf) + log(cvg_factor)]
} else {
cvg_new[, cvg := sum(log(c(cvg_arf[1], cvg_factor))), by = f_idx]
}

cvg_new <- unique(cvg_new[, .(f_idx, c_idx, cvg)])

Expand Down

0 comments on commit 9af0a8f

Please sign in to comment.