From 451fa167ea35f70e7b32486bb16e5d3318a533e8 Mon Sep 17 00:00:00 2001 From: Rishabh Garg <56191449+RishabhGarg108@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:08:54 +0530 Subject: [PATCH] Change names of functions --- .../best_binary_numeric_split_impl.hpp | 16 ++++++++-------- src/mlpack/methods/decision_tree/mse_gain.hpp | 17 +++++++---------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/mlpack/methods/decision_tree/best_binary_numeric_split_impl.hpp b/src/mlpack/methods/decision_tree/best_binary_numeric_split_impl.hpp index 2aacd38439..8d8031293c 100644 --- a/src/mlpack/methods/decision_tree/best_binary_numeric_split_impl.hpp +++ b/src/mlpack/methods/decision_tree/best_binary_numeric_split_impl.hpp @@ -390,9 +390,9 @@ double BestBinaryNumericSplit::SplitIfBetter( bestFoundGain *= data.n_elem; } - // Precomputing various statistics to efficiently compute gain values for - // all possible splits. - fitnessFunction.CalculateStatistics(sortedResponses, + // Initialize and precompute various statistics to efficiently compute gain + // values for all possible splits. + fitnessFunction.BinaryScanInitialize(sortedResponses, sortedWeights, minimum); // Loop through all possible split points, choosing the best one. @@ -404,8 +404,8 @@ double BestBinaryNumericSplit::SplitIfBetter( rightChildWeight -= sortedWeights[index - 1]; } - // Update statistics for the current index. - fitnessFunction.UpdateStatistics(sortedResponses, + // Steps through the current index and updates the cached data. + fitnessFunction.BinaryStep(sortedResponses, sortedWeights, index - 1); // Make sure that the value has changed. @@ -413,9 +413,9 @@ double BestBinaryNumericSplit::SplitIfBetter( continue; // Calculate the gain for the left and right child. - auto value = fitnessFunction.Evaluate(); - const double leftGain = std::get<0>(value); - const double rightGain = std::get<1>(value); + auto binaryGains = fitnessFunction.BinaryGains(); + const double leftGain = std::get<0>(binaryGains); + const double rightGain = std::get<1>(binaryGains); double gain; if (UseWeights) diff --git a/src/mlpack/methods/decision_tree/mse_gain.hpp b/src/mlpack/methods/decision_tree/mse_gain.hpp index 4226e9699f..2b4e058eb2 100644 --- a/src/mlpack/methods/decision_tree/mse_gain.hpp +++ b/src/mlpack/methods/decision_tree/mse_gain.hpp @@ -106,7 +106,7 @@ class MSEGain * {\dfrac{\sum\limits_{j=1}^n X_j}{n}}^2 * @f} */ - std::tuple Evaluate() + std::tuple BinaryGains() { double mseLeft = leftSumSquares / leftSize - leftMean * leftMean; double mseRight = (totalSumSquares - leftSumSquares) / rightSize @@ -124,9 +124,9 @@ class MSEGain * @param minimum The minimum number of elements in a leaf. */ template - void CalculateStatistics(const ResponsesType& responses, - const WeightVecType& weights, - const size_t minimum) + void BinaryScanInitialize(const ResponsesType& responses, + const WeightVecType& weights, + const size_t minimum) { typedef typename ResponsesType::elem_type RType; typedef typename WeightVecType::elem_type WType; @@ -141,9 +141,6 @@ class MSEGain if (UseWeights) { - // Do I need to document that the % symbol does the elementwise multiplication? - // It might be misleading to general developers who might confuse it with modulo - // operator. totalSumSquares = arma::accu(weights % arma::square(responses)); for (size_t i = 0; i < minimum - 1; ++i) { @@ -206,9 +203,9 @@ class MSEGain * @param index The current index. */ template - void UpdateStatistics(const ResponsesType& responses, - const WeightVecType& weights, - const size_t index) + void BinaryStep(const ResponsesType& responses, + const WeightVecType& weights, + const size_t index) { typedef typename ResponsesType::elem_type RType; typedef typename WeightVecType::elem_type WType;