From f9b1733811314d9325d714af6f4d7425681025f9 Mon Sep 17 00:00:00 2001 From: JOSEPH MURE Date: Mon, 26 Jan 2026 18:13:16 +0100 Subject: [PATCH] Forest::loadDataForPrediction A method to load data after a trained forest and start prediction mode --- src/Forest.cpp | 20 ++++++++++++++++++++ src/Forest.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/Forest.cpp b/src/Forest.cpp index 95edd6f7..d5279eff 100644 --- a/src/Forest.cpp +++ b/src/Forest.cpp @@ -281,6 +281,26 @@ void Forest::init(std::unique_ptr input_data, uint mtry, std::string outpu } } +void Forest::loadDataForPrediction(std::unique_ptr input_data, std::vector& is_ordered_variable, bool predict_all) { + this->data = std::move(input_data); + this->prediction_mode = true; + this->predict_all = predict_all; + + // Set number of samples and variables + num_samples = data->getNumRows(); + num_independent_variables = data->getNumCols(); + + // Set unordered factor variables + data->setIsOrderedVariable(is_ordered_variable); + + initInternal(); + + // Permute samples for corrected Gini importance + if (importance_mode == IMP_GINI_CORRECTED) { + data->permuteSampleIDs(random_number_generator); + } +} + void Forest::run(bool verbose, bool compute_oob_error) { if (prediction_mode) { diff --git a/src/Forest.h b/src/Forest.h index 2ad3083b..d594cbf7 100644 --- a/src/Forest.h +++ b/src/Forest.h @@ -65,6 +65,7 @@ class Forest { bool order_snps, uint max_depth, const std::vector& regularization_factor, bool regularization_usedepth, bool node_stats); virtual void initInternal() = 0; + void loadDataForPrediction(std::unique_ptr input_data, std::vector& is_ordered_variable, bool predict_all = false); // Grow or predict void run(bool verbose, bool compute_oob_error);