CLN Remove parent negative loss calculation from for loop to improve performance
@@ -429,12 +429,15 @@ cdef class Splitter:
Y_DTYPE_C sum_hessian_right
Y_DTYPE_C sum_gradient_left
Y_DTYPE_C sum_gradient_right
+ Y_DTYPE_C negative_loss_current_node
Y_DTYPE_C gain
split_info_struct best_split
best_split.gain = -1.
sum_gradient_left, sum_hessian_left = 0., 0.
n_samples_left = 0
+ negative_loss_current_node = negative_loss(sum_gradients,
+ sum_hessians, self.l2_regularization)
for bin_idx in range(self.actual_n_bins[feature_idx]):
n_samples_left += histograms[feature_idx, bin_idx].count
@@ -464,7 +467,7 @@ cdef class Splitter:
gain = _split_gain(sum_gradient_left, sum_hessian_left,
sum_gradient_right, sum_hessian_right,
- sum_gradients, sum_hessians,
+ negative_loss_current_node,
self.l2_regularization)
if gain > best_split.gain and gain > self.min_gain_to_split:
@@ -486,8 +489,7 @@ cdef inline Y_DTYPE_C _split_gain(
Y_DTYPE_C sum_hessian_left,
Y_DTYPE_C sum_gradient_right,
Y_DTYPE_C sum_hessian_right,
- Y_DTYPE_C sum_gradients,
- Y_DTYPE_C sum_hessians,
+ Y_DTYPE_C negative_loss_current_node,
Y_DTYPE_C l2_regularization) nogil:
"""Loss reduction
@@ -504,7 +506,7 @@ cdef inline Y_DTYPE_C _split_gain(
l2_regularization)
gain += negative_loss(sum_gradient_right, sum_hessian_right,
l2_regularization)
- gain -= negative_loss(sum_gradients, sum_hessians, l2_regularization)
+ gain -= negative_loss_current_node
return gain
cdef inline Y_DTYPE_C negative_loss(
