From f755ea9348acecf92f8dd7d140d3a4b2d3c49388 Mon Sep 17 00:00:00 2001 From: bcjaeger Date: Sat, 7 Oct 2023 20:02:43 -0400 Subject: [PATCH] drop global verbosity --- src/ForestSurvival.cpp | 2 +- src/Tree.cpp | 42 ++++++++++++++--------------------- src/globals.h | 2 -- tests/testthat/test-oobag.R | 6 ++--- tests/testthat/test-orsf_pd.R | 16 +++++++++++++ 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/ForestSurvival.cpp b/src/ForestSurvival.cpp index 93291546..9b9335f6 100644 --- a/src/ForestSurvival.cpp +++ b/src/ForestSurvival.cpp @@ -49,7 +49,7 @@ void ForestSurvival::load( this->pd_x_cols = pd_x_cols; this->pd_probs = pd_probs; - if(VERBOSITY > 0){ + if(verbosity > 2){ Rcout << "---- loading forest from input list ----"; Rcout << std::endl << std::endl; } diff --git a/src/Tree.cpp b/src/Tree.cpp index 1fe8426d..98528d4a 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -315,12 +315,12 @@ } - if(VERBOSITY > 1){ + if(verbosity > 4){ mat x_print = x_inbag.rows(rows_node); - Rcout << "Column " << j << " was sampled but "; - Rcout << "unique values of column " << j << " are "; - Rcout << unique(x_print.col(j)) << std::endl; + Rcout << " -- Column " << j << " was sampled but "; + Rcout << "its unique values are " << unique(x_print.col(j)); + Rcout << std::endl; } @@ -371,10 +371,6 @@ double n_obs = 0; - if(VERBOSITY > 1){ - Rcout << "----- finding lower bound for cut-points -----" << std::endl; - } - // stop at end-1 b/c we access it+1 in lincomb_sort for(it = lincomb_sort.begin(); it < lincomb_sort.end()-1; ++it){ @@ -388,10 +384,10 @@ if(n_obs >= leaf_min_obs) { - if(VERBOSITY > 0){ + if(verbosity > 3){ Rcout << std::endl; - Rcout << "lower cutpoint: " << lincomb(*it) << std::endl; - Rcout << " - n_obs, left node: " << n_obs << std::endl; + Rcout << " -- lower cutpoint: " << lincomb(*it) << std::endl; + Rcout << " - n_obs, left node: " << n_obs << std::endl; Rcout << std::endl; } @@ -407,8 +403,8 @@ if(it == lincomb_sort.end()-1) { - if(VERBOSITY > 1){ - Rcout << "Could not find a valid cut-point" << std::endl; + if(verbosity > 3){ + Rcout << " -- Could not find a valid cut-point" << std::endl; } return; @@ -421,10 +417,6 @@ // reset before finding the upper limit n_obs=0; - if(VERBOSITY > 1){ - Rcout << "----- finding upper bound for cut-points -----" << std::endl; - } - // stop at beginning+1 b/c we access it-1 in lincomb_sort for(it = lincomb_sort.end()-1; it >= lincomb_sort.begin()+1; --it){ @@ -444,10 +436,10 @@ --it; - if(VERBOSITY > 0){ + if(verbosity > 3){ Rcout << std::endl; - Rcout << "upper cutpoint: " << lincomb(*it) << std::endl; - Rcout << " - n_obs, right node: " << n_obs << std::endl; + Rcout << " -- upper cutpoint: " << lincomb(*it) << std::endl; + Rcout << " - n_obs, right node: " << n_obs << std::endl; Rcout << std::endl; } @@ -466,8 +458,8 @@ if(j > k){ - if(VERBOSITY > 0) { - Rcout << "Could not find valid cut-points" << std::endl; + if(verbosity > 2) { + Rcout << " -- Could not find valid cut-points" << std::endl; } return; @@ -698,10 +690,10 @@ double accuracy_permuted = compute_prediction_accuracy(pred_values); - if(VERBOSITY>1){ - Rcout << "prediction accuracy after noising " << pred_col << ": "; + if(verbosity > 3){ + Rcout << " -- prediction accuracy after noising " << pred_col << ": "; Rcout << accuracy_permuted << std::endl; - Rcout << " - mean leaf pred: "; + Rcout << " - mean leaf pred: "; Rcout << mean(conv_to::from(pred_leaf)); Rcout << std::endl << std::endl; } diff --git a/src/globals.h b/src/globals.h index c684b813..22c68d30 100644 --- a/src/globals.h +++ b/src/globals.h @@ -97,8 +97,6 @@ const PredType DEFAULT_PRED_TYPE = PRED_RISK; - const int VERBOSITY = 0; - // Interval to print progress in seconds const double STATUS_INTERVAL = 1.0; diff --git a/tests/testthat/test-oobag.R b/tests/testthat/test-oobag.R index db96150a..2d876c21 100644 --- a/tests/testthat/test-oobag.R +++ b/tests/testthat/test-oobag.R @@ -3,14 +3,12 @@ fit_custom_oobag <- orsf(pbc_orsf, formula = Surv(time, status) ~ . - id, n_tree = 100, oobag_fun = oobag_c_survival, - tree_seeds = 1:100, - verbose_progress = 0) + tree_seeds = 1:100) fit_standard_oobag <- orsf(pbc_orsf, formula = Surv(time, status) ~ . - id, n_tree = 100, - tree_seeds = 1:100, - verbose_progress = 0) + tree_seeds = 1:100) testthat::expect_equal( fit_custom_oobag$forest$rows_oobag, diff --git a/tests/testthat/test-orsf_pd.R b/tests/testthat/test-orsf_pd.R index 9a219b6e..2a8393c4 100644 --- a/tests/testthat/test-orsf_pd.R +++ b/tests/testthat/test-orsf_pd.R @@ -209,5 +209,21 @@ test_that( # } # ) +# bili_seq <- seq(1, 5, length.out=20) +# +# microbenchmark::microbenchmark( +# pd_reference = partial(fit, +# pred.var = "bili", +# pred.grid = data.frame(bili = bili_seq), +# pred.fun = pred_aorsf, +# plot = FALSE, +# ice = TRUE, +# train = pbc_orsf), +# pd_aorsf = orsf_ice_new(fit, +# new_data = pbc_orsf, +# pred_spec = list(bili=bili_seq), +# pred_horizon = 1000, +# expand_grid = TRUE) +# )