Medial Code Documentation
Loading...
Searching...
No Matches
constraints.h
1
4#ifndef XGBOOST_TREE_CONSTRAINTS_H_
5#define XGBOOST_TREE_CONSTRAINTS_H_
6
7#include <string>
8#include <unordered_set>
9#include <vector>
10
11#include "param.h"
12#include "xgboost/base.h"
13
14namespace xgboost {
21 protected:
22 // interaction_constraints_[constraint_id] contains a single interaction
23 // constraint, which specifies a group of feature IDs that can interact
24 // with each other
25 std::vector< std::unordered_set<bst_feature_t> > interaction_constraints_;
26 // int_cont_[nid] contains the set of all feature IDs that are allowed to
27 // be used for a split at node nid
28 std::vector< std::unordered_set<bst_feature_t> > node_constraints_;
29 // splits_[nid] contains the set of all feature IDs that have been used for
30 // splits in node nid and its parents
31 std::vector< std::unordered_set<bst_feature_t> > splits_;
32 // string passed by user.
33 std::string interaction_constraint_str_;
34 // number of features in DMatrix/Booster
35 bst_feature_t n_features_;
36 bool enabled_{false};
37
38 void SplitImpl(int32_t node_id, bst_feature_t feature_id, bst_node_t left_id,
39 bst_node_t right_id);
40
41 public:
43 void Split(int32_t node_id, bst_feature_t feature_id, bst_node_t left_id,
44 bst_node_t right_id) {
45 if (!enabled_) {
46 return;
47 } else {
48 this->SplitImpl(node_id, feature_id, left_id, right_id);
49 }
50 }
51
52 bool Query(bst_node_t nid, bst_feature_t fid) const {
53 if (!enabled_) { return true; }
54 return node_constraints_.at(nid).find(fid) != node_constraints_.at(nid).cend();
55 }
56
57 void Reset();
58
59 void Configure(tree::TrainParam const& param, bst_feature_t const n_features);
60};
61} // namespace xgboost
62
63#endif // XGBOOST_TREE_CONSTRAINTS_H_
Feature interaction constraint implementation for CPU tree updaters.
Definition constraints.h:20
Copyright 2015-2023 by XGBoost Contributors.
namespace of xgboost
Definition base.h:90
uint32_t bst_feature_t
Type for data column (feature) index.
Definition base.h:101
std::int32_t bst_node_t
Type for tree node index.
Definition base.h:112
training parameters for regression tree
Definition param.h:28
Copyright 2014-2023 by XGBoost Contributors.