Module utils

Module utils 

Source

Functions§

between
Test if v is contained within the range i and j
bound_to_parent
constrained_weight
Calculate the constraint weight given bounds and a constraint.
cull_gain
Cull gain, if it does not conform to constraints.
fast_f64_sum
Fast summation, but using f64 as the internal representation so that we don’t have issues with the precision. This way, we can still work with f32 values, but get the correct sum value.
fast_sum
Fast summation, ends up being roughly 8 to 10 times faster than values.iter().copied().sum(). Shamelessly stolen from https://stackoverflow.com/a/67191480
fmt_vec_output
gain
Calculate the gain given the gradient and hessian of the node.
gain_given_weight
Calculate the gain of a split given a specific weight value. This is for if the weight has to be constrained, for example for monotonicity constraints.
is_missing
Calculate if a value is missing.
items_to_strings
Create a string of all available items.
l1_regularization
Calculate l1 regularization
map_bin
Return the index of the first value in a sorted vector that is greater than a provided value.
missing_compare
Function to compare a value to our split value. Our split value will never be missing (0), thus we don’t have to worry about that.
naive_sum
odds
Convert Log odds to probability
percentiles
Naive weighted percentiles calculation.
pivot_on_split
Provided a list of index values, pivot those values around a specific split value so all of the values less than the split value are on one side, and then all of the values greater than or equal to the split value are above.
pivot_on_split_exclude_missing
Provided a list of index values, pivot those values around a specific split value so all of the values less than the split value are on one side, and then all of the values greater than or equal to the split value are above. Missing values, will be pushed to the bottom, a value of zero is missing in this case. Returns a tuple, the first is the first non-missing value index, the second is the first value that is greater than our provided split value.
precision_round
validate_float_parameter
validate_not_nan_vec
validate_positive_float_parameter
validate_positive_not_nan_vec
validate_positive_vec
weight
Calculate the weight of a given node, given the sum of the gradients, and the hessians in a node.