Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tree to if-else #5422

Merged
merged 4 commits into from
Aug 25, 2022
Merged

update tree to if-else #5422

merged 4 commits into from
Aug 25, 2022

Conversation

jmoralez
Copy link
Collaborator

@jmoralez jmoralez commented Aug 15, 2022

Updates the tree to if else code to match the code in tree.h:

  • Numerical Split:
    inline int NumericalDecision(double fval, int node) const {
    uint8_t missing_type = GetMissingType(decision_type_[node]);
    if (std::isnan(fval) && missing_type != MissingType::NaN) {
    fval = 0.0f;
    }
    if ((missing_type == MissingType::Zero && IsZero(fval))
    || (missing_type == MissingType::NaN && std::isnan(fval))) {
    if (GetDecisionType(decision_type_[node], kDefaultLeftMask)) {
    return left_child_[node];
    } else {
    return right_child_[node];
    }
    }
    if (fval <= threshold_[node]) {
    return left_child_[node];
    } else {
    return right_child_[node];
    }
    }
  • Categorical Split:
    inline int CategoricalDecision(double fval, int node) const {
    int int_fval;
    if (std::isnan(fval)) {
    return right_child_[node];
    } else {
    int_fval = static_cast<int>(fval);
    if (int_fval < 0) {
    return right_child_[node];
    }
    }
    int cat_idx = static_cast<int>(threshold_[node]);
    if (Common::FindInBitset(cat_threshold_.data() + cat_boundaries_[cat_idx],
    cat_boundaries_[cat_idx + 1] - cat_boundaries_[cat_idx], int_fval)) {
    return left_child_[node];
    }
    return right_child_[node];
    }

@jmoralez jmoralez marked this pull request as ready for review August 16, 2022 02:26
Copy link
Collaborator

@shiyu1994 shiyu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix. Quite clear to me!

@shiyu1994 shiyu1994 merged commit 39eb041 into master Aug 25, 2022
@shiyu1994 shiyu1994 deleted the update-if-else branch August 25, 2022 13:48
@jameslamb jameslamb mentioned this pull request Oct 7, 2022
40 tasks
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants