@@ -57,6 +57,7 @@ class Term
5757 void cleanup_after_fit ();
5858 void cleanup_when_this_term_was_added_as_a_given_term ();
5959 void make_term_ineligible ();
60+ void determine_if_can_be_used_as_a_given_term (const VectorXd &x);
6061
6162public:
6263 // fields
@@ -75,6 +76,7 @@ class Term
7576 size_t ineligible_boosting_steps;
7677 VectorXd values_discretized; // Discretized values based on split_point=nan
7778 VectorXd sample_weight_discretized; // Discretized sample_weight based on split_point=nan
79+ bool can_be_used_as_a_given_term;
7880
7981 // methods
8082 Term (size_t base_term=0 ,const std::vector<Term> &given_terms=std::vector<Term>(0 ),double split_point=NAN_DOUBLE,bool direction_right=false ,double coefficient=0 );
@@ -97,14 +99,15 @@ class Term
9799// Regular constructor
98100Term::Term (size_t base_term,const std::vector<Term> &given_terms,double split_point,bool direction_right,double coefficient):
99101name{" " },base_term{base_term},given_terms{given_terms},split_point{split_point},direction_right{direction_right},coefficient{coefficient},
100- split_point_search_errors_sum{std::numeric_limits<double >::infinity ()},ineligible_boosting_steps{0 }
102+ split_point_search_errors_sum{std::numeric_limits<double >::infinity ()},ineligible_boosting_steps{0 },can_be_used_as_a_given_term{ false }
101103{
102104}
103105
104106// Copy constructor
105107Term::Term (const Term &other):
106108name{other.name },base_term{other.base_term },given_terms{other.given_terms },split_point{other.split_point },direction_right{other.direction_right },
107- coefficient{other.coefficient },coefficient_steps{other.coefficient_steps },split_point_search_errors_sum{other.split_point_search_errors_sum },ineligible_boosting_steps{0 }
109+ coefficient{other.coefficient },coefficient_steps{other.coefficient_steps },split_point_search_errors_sum{other.split_point_search_errors_sum },
110+ ineligible_boosting_steps{0 },can_be_used_as_a_given_term{other.can_be_used_as_a_given_term }
108111{
109112}
110113
@@ -180,6 +183,7 @@ void Term::estimate_split_point(const MatrixXd &X,const VectorXd &negative_gradi
180183 estimate_split_point_on_discretized_data ();
181184 estimate_coefficient_and_error_on_all_data ();
182185 cleanup_after_estimate_split_point ();
186+ determine_if_can_be_used_as_a_given_term (X.col (base_term));
183187}
184188
185189// Calculate indices that get zeroed out during calculate() because of given terms. Also calculates indices of those observations that do not.
@@ -642,6 +646,20 @@ void Term::cleanup_after_estimate_split_point()
642646 errors_initial.resize (0 );
643647}
644648
649+ void Term::determine_if_can_be_used_as_a_given_term (const VectorXd &x)
650+ {
651+ VectorXd values{calculate_without_interactions (x)};
652+ can_be_used_as_a_given_term = false ;
653+ for (auto &value:values)
654+ {
655+ if (is_approximately_zero (value))
656+ {
657+ can_be_used_as_a_given_term=true ;
658+ break ;
659+ }
660+ }
661+ }
662+
645663void Term::cleanup_after_fit ()
646664{
647665 bins_start_index.clear ();
0 commit comments