Skip to content

Commit

Permalink
Leverage USE_MC for efficiency.
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesAuguste committed Aug 23, 2020
1 parent bb6033b commit 4e1adbc
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/treelearner/feature_histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ class FeatureHistogram {
double best_sum_left_gradient = 0;
double best_sum_left_hessian = 0;
double gain_shift;
constraints->InitCumulativeConstraints(true);
if (USE_MC) {
constraints->InitCumulativeConstraints(true);
}
if (USE_SMOOTHING) {
gain_shift = GetLeafGainGivenOutput<USE_L1>(
sum_gradient, sum_hessian, meta_->config->lambda_l1, meta_->config->lambda_l2, parent_output);
Expand Down Expand Up @@ -866,12 +868,15 @@ class FeatureHistogram {
data_size_t best_left_count = 0;
uint32_t best_threshold = static_cast<uint32_t>(meta_->num_bin);
const double cnt_factor = num_data / sum_hessian;

BasicConstraint best_right_constraints;
BasicConstraint best_left_constraints;

bool constraint_update_necessary =
constraints->ConstraintDifferentDependingOnThreshold();
constraints->InitCumulativeConstraints(REVERSE);
USE_MC && constraints->ConstraintDifferentDependingOnThreshold();

if (USE_MC) {
constraints->InitCumulativeConstraints(REVERSE);
}

if (REVERSE) {
double sum_right_gradient = 0.0f;
Expand Down Expand Up @@ -920,7 +925,7 @@ class FeatureHistogram {
}
}

if (constraint_update_necessary) {
if (USE_MC && constraint_update_necessary) {
constraints->Update(t + offset);
}

Expand All @@ -946,8 +951,10 @@ class FeatureHistogram {
// left is <= threshold, right is > threshold. so this is t-1
best_threshold = static_cast<uint32_t>(t - 1 + offset);
best_gain = current_gain;
best_right_constraints = (constraints->RightToBasicConstraint());
best_left_constraints = (constraints->LeftToBasicConstraint());
if (USE_MC) {
best_right_constraints = (constraints->RightToBasicConstraint());
best_left_constraints = (constraints->LeftToBasicConstraint());
}
}
}
} else {
Expand Down Expand Up @@ -1032,8 +1039,10 @@ class FeatureHistogram {
best_sum_left_hessian = sum_left_hessian;
best_threshold = static_cast<uint32_t>(t + offset);
best_gain = current_gain;
best_right_constraints = (constraints->RightToBasicConstraint());
best_left_constraints = (constraints->LeftToBasicConstraint());
if (USE_MC) {
best_right_constraints = (constraints->RightToBasicConstraint());
best_left_constraints = (constraints->LeftToBasicConstraint());
}
}
}
}
Expand Down

0 comments on commit 4e1adbc

Please sign in to comment.