25#ifndef STOCHTREE_PARTITION_TRACKER_H_
26#define STOCHTREE_PARTITION_TRACKER_H_
28#include <stochtree/data.h>
29#include <stochtree/ensemble.h>
30#include <stochtree/log.h>
31#include <stochtree/openmp_utils.h>
32#include <stochtree/tree.h>
39class SampleNodeMapper;
40class SamplePredMapper;
41class UnsortedNodeSampleTracker;
42class SortedNodeSampleTracker;
43class FeaturePresortRootContainer;
56 ForestTracker(Eigen::MatrixXd& covariates, std::vector<FeatureType>& feature_types,
int num_trees,
int num_observations);
59 void AssignAllSamplesToRoot();
60 void AssignAllSamplesToRoot(int32_t tree_num);
61 void AssignAllSamplesToConstantPrediction(
double value);
62 void AssignAllSamplesToConstantPrediction(int32_t tree_num,
double value);
66 void ResetRoot(Eigen::MatrixXd& covariates, std::vector<FeatureType>& feature_types, int32_t tree_num);
67 void AddSplit(Eigen::MatrixXd& covariates,
TreeSplit& split, int32_t split_feature, int32_t tree_id, int32_t split_node_id, int32_t left_node_id, int32_t right_node_id,
bool keep_sorted =
false,
int num_threads = -1);
68 void RemoveSplit(Eigen::MatrixXd& covariates,
Tree* tree, int32_t tree_id, int32_t split_node_id, int32_t left_node_id, int32_t right_node_id,
bool keep_sorted =
false);
69 double GetSamplePrediction(data_size_t sample_id);
70 double GetTreeSamplePrediction(data_size_t sample_id,
int tree_id);
71 void UpdateVarWeightsFromInternalPredictions(
ForestDataset& dataset);
72 void SetSamplePrediction(data_size_t sample_id,
double value);
73 void SetTreeSamplePrediction(data_size_t sample_id,
int tree_id,
double value);
74 void SyncPredictions();
75 data_size_t GetNodeId(
int observation_num,
int tree_num);
76 data_size_t UnsortedNodeBegin(
int tree_id,
int node_id);
77 data_size_t UnsortedNodeEnd(
int tree_id,
int node_id);
78 data_size_t UnsortedNodeSize(
int tree_id,
int node_id);
79 data_size_t SortedNodeBegin(
int node_id,
int feature_id);
80 data_size_t SortedNodeEnd(
int node_id,
int feature_id);
81 data_size_t SortedNodeSize(
int node_id,
int feature_id);
82 std::vector<data_size_t>::iterator UnsortedNodeBeginIterator(
int tree_id,
int node_id);
83 std::vector<data_size_t>::iterator UnsortedNodeEndIterator(
int tree_id,
int node_id);
84 std::vector<data_size_t>::iterator SortedNodeBeginIterator(
int node_id,
int feature_id);
85 std::vector<data_size_t>::iterator SortedNodeEndIterator(
int node_id,
int feature_id);
87 SampleNodeMapper* GetSampleNodeMapper() {
return sample_node_mapper_.get();}
88 UnsortedNodeSampleTracker* GetUnsortedNodeSampleTracker() {
return unsorted_node_sample_tracker_.get();}
89 SortedNodeSampleTracker* GetSortedNodeSampleTracker() {
return sorted_node_sample_tracker_.get();}
90 int GetNumObservations() {
return num_observations_;}
91 int GetNumTrees() {
return num_trees_;}
92 int GetNumFeatures() {
return num_features_;}
93 bool Initialized() {
return initialized_;}
96 std::vector<double> sum_predictions_;
98 std::unique_ptr<SamplePredMapper> sample_pred_mapper_;
100 std::unique_ptr<SampleNodeMapper> sample_node_mapper_;
104 std::unique_ptr<UnsortedNodeSampleTracker> unsorted_node_sample_tracker_;
108 std::unique_ptr<FeaturePresortRootContainer> presort_container_;
109 std::unique_ptr<SortedNodeSampleTracker> sorted_node_sample_tracker_;
110 std::vector<FeatureType> feature_types_;
112 int num_observations_;
114 bool initialized_{
false};
116 void UpdatePredictionsInternal(TreeEnsemble* ensemble, Eigen::MatrixXd& covariates, Eigen::MatrixXd& basis);
117 void UpdatePredictionsInternal(TreeEnsemble* ensemble, Eigen::MatrixXd& covariates);
118 void UpdateSampleTrackersInternal(TreeEnsemble& forest, Eigen::MatrixXd& covariates, Eigen::MatrixXd& basis);
119 void UpdateSampleTrackersInternal(TreeEnsemble& forest, Eigen::MatrixXd& covariates);
120 void UpdateSampleTrackersResidualInternalBasis(TreeEnsemble& forest, ForestDataset& dataset, ColumnVector& residual,
bool is_mean_model);
121 void UpdateSampleTrackersResidualInternalNoBasis(TreeEnsemble& forest, ForestDataset& dataset, ColumnVector& residual,
bool is_mean_model);
128 num_trees_ = num_trees;
129 num_observations_ = num_observations;
131 tree_preds_.resize(num_trees_);
132 for (
int j = 0; j < num_trees_; j++) {
133 tree_preds_[j].resize(num_observations_);
137 inline double GetPred(data_size_t sample_id,
int tree_id) {
138 CHECK_LT(sample_id, num_observations_);
139 CHECK_LT(tree_id, num_trees_);
140 return tree_preds_[tree_id][sample_id];
143 inline void SetPred(data_size_t sample_id,
int tree_id,
double value) {
144 CHECK_LT(sample_id, num_observations_);
145 CHECK_LT(tree_id, num_trees_);
146 tree_preds_[tree_id][sample_id] = value;
149 inline int NumTrees() {
return num_trees_;}
151 inline int NumObservations() {
return num_observations_;}
153 inline void AssignAllSamplesToConstantPrediction(
int tree_id,
double value) {
154 for (data_size_t i = 0; i < num_observations_; i++) {
155 tree_preds_[tree_id][i] = value;
160 std::vector<std::vector<double>> tree_preds_;
162 data_size_t num_observations_;
169 num_trees_ = num_trees;
170 num_observations_ = num_observations;
172 tree_observation_indices_.resize(num_trees_);
173 for (
int j = 0; j < num_trees_; j++) {
174 tree_observation_indices_[j].resize(num_observations_);
179 num_trees_ = other.NumTrees();
180 num_observations_ = other.NumObservations();
182 tree_observation_indices_.resize(num_trees_);
183 for (
int j = 0; j < num_trees_; j++) {
184 tree_observation_indices_[j].resize(num_observations_);
185 for (
int i = 0; i < num_observations_; i++) {
186 tree_observation_indices_[j][i] = other.GetNodeId(i, j);
191 void AddSplit(Eigen::MatrixXd& covariates,
TreeSplit& split, int32_t split_feature, int32_t tree_id, int32_t split_node_id, int32_t left_node_id, int32_t right_node_id) {
192 CHECK_EQ(num_observations_, covariates.rows());
194 for (
int i = 0; i < num_observations_; i++) {
195 if (tree_observation_indices_[tree_id][i] == split_node_id) {
196 auto fvalue = covariates(i, split_feature);
198 tree_observation_indices_[tree_id][i] = left_node_id;
200 tree_observation_indices_[tree_id][i] = right_node_id;
206 inline data_size_t GetNodeId(data_size_t sample_id,
int tree_id) {
207 CHECK_LT(sample_id, num_observations_);
208 CHECK_LT(tree_id, num_trees_);
209 return tree_observation_indices_[tree_id][sample_id];
212 inline void SetNodeId(data_size_t sample_id,
int tree_id,
int node_id) {
213 CHECK_LT(sample_id, num_observations_);
214 CHECK_LT(tree_id, num_trees_);
215 tree_observation_indices_[tree_id][sample_id] = node_id;
218 inline int NumTrees() {
return num_trees_;}
220 inline int NumObservations() {
return num_observations_;}
222 inline void AssignAllSamplesToRoot(
int tree_id) {
223 for (data_size_t i = 0; i < num_observations_; i++) {
224 tree_observation_indices_[tree_id][i] = 0;
229 std::vector<std::vector<int>> tree_observation_indices_;
231 data_size_t num_observations_;
243 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int left_node_id,
int right_node_id,
int feature_split,
TreeSplit& split);
246 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int left_node_id,
int right_node_id,
int feature_split,
double split_value);
249 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int left_node_id,
int right_node_id,
int feature_split, std::vector<std::uint32_t>
const& category_list);
295 std::vector<data_size_t> node_begin_;
296 std::vector<data_size_t> node_length_;
297 std::vector<int32_t> parent_nodes_;
298 std::vector<int32_t> left_nodes_;
299 std::vector<int32_t> right_nodes_;
300 int num_nodes_, num_deleted_nodes_;
301 std::vector<int> deleted_nodes_;
304 void ExpandNodeTrackingVectors(
int node_id,
int left_node_id,
int right_node_id, data_size_t node_start_idx, data_size_t num_left, data_size_t num_right);
305 void ConvertLeafParentToLeaf(
int node_id);
312 feature_partitions_.resize(num_trees);
313 num_trees_ = num_trees;
314 for (
int i = 0; i < num_trees; i++) {
323 void PartitionTreeNode(Eigen::MatrixXd& covariates,
int tree_id,
int node_id,
int left_node_id,
int right_node_id,
int feature_split,
TreeSplit& split) {
324 return feature_partitions_[tree_id]->PartitionNode(covariates, node_id, left_node_id, right_node_id, feature_split, split);
328 void PartitionTreeNode(Eigen::MatrixXd& covariates,
int tree_id,
int node_id,
int left_node_id,
int right_node_id,
int feature_split,
double split_value) {
329 return feature_partitions_[tree_id]->PartitionNode(covariates, node_id, left_node_id, right_node_id, feature_split, split_value);
333 void PartitionTreeNode(Eigen::MatrixXd& covariates,
int tree_id,
int node_id,
int left_node_id,
int right_node_id,
int feature_split, std::vector<std::uint32_t>
const& category_list) {
334 return feature_partitions_[tree_id]->PartitionNode(covariates, node_id, left_node_id, right_node_id, feature_split, category_list);
344 return feature_partitions_[tree_id]->PruneNodeToLeaf(node_id);
349 return feature_partitions_[tree_id]->IsLeaf(node_id);
354 return feature_partitions_[tree_id]->IsValidNode(node_id);
359 return feature_partitions_[tree_id]->LeftNodeIsLeaf(node_id);
364 return feature_partitions_[tree_id]->RightNodeIsLeaf(node_id);
369 return feature_partitions_[tree_id]->NodeBegin(node_id);
373 data_size_t
NodeEnd(
int tree_id,
int node_id) {
374 return feature_partitions_[tree_id]->NodeEnd(node_id);
377 std::vector<data_size_t>::iterator NodeBeginIterator(
int tree_id,
int node_id) {
378 data_size_t node_begin = feature_partitions_[tree_id]->NodeBegin(node_id);
379 auto begin_iter = feature_partitions_[tree_id]->indices_.begin();
380 return begin_iter + node_begin;
383 std::vector<data_size_t>::iterator NodeEndIterator(
int tree_id,
int node_id) {
384 int node_end = feature_partitions_[tree_id]->NodeEnd(node_id);
385 auto begin_iter = feature_partitions_[tree_id]->indices_.begin();
386 return begin_iter + node_end;
391 return feature_partitions_[tree_id]->NodeSize(node_id);
396 return feature_partitions_[tree_id]->Parent(node_id);
401 return feature_partitions_[tree_id]->LeftNode(node_id);
406 return feature_partitions_[tree_id]->RightNode(node_id);
411 return feature_partitions_[tree_id]->NodeIndices(node_id);
416 feature_partitions_[tree_id]->UpdateObservationMapping(node_id, tree_id, sample_node_mapper);
421 std::vector<int> leaves = tree->
GetLeaves();
423 for (
int i = 0; i < leaves.size(); i++) {
437 std::vector<std::unique_ptr<FeatureUnsortedPartition>> feature_partitions_;
444 NodeOffsetSize(data_size_t node_offset, data_size_t node_size) : node_begin_{node_offset}, node_size_{node_size}, presorted_{
false} {
445 node_end_ = node_begin_ + node_size_;
450 void SetSorted() {presorted_ =
true;}
452 bool IsSorted() {
return presorted_;}
454 data_size_t Begin() {
return node_begin_;}
456 data_size_t End() {
return node_end_;}
458 data_size_t Size() {
return node_size_;}
461 data_size_t node_begin_;
462 data_size_t node_size_;
463 data_size_t node_end_;
482 FeaturePresortRoot(Eigen::MatrixXd& covariates, int32_t feature_index, FeatureType feature_type) {
483 feature_index_ = feature_index;
484 ArgsortRoot(covariates);
489 void ArgsortRoot(Eigen::MatrixXd& covariates) {
490 data_size_t num_obs = covariates.rows();
493 if (feature_sort_indices_.size() != num_obs){
494 feature_sort_indices_.resize(num_obs, 0);
496 std::iota(feature_sort_indices_.begin(), feature_sort_indices_.end(), 0);
501 auto comp_op = [&](
size_t const &l,
size_t const &r) {
return std::less<double>{}(covariates(l, feature_index_), covariates(r, feature_index_)); };
502 std::stable_sort(feature_sort_indices_.begin(), feature_sort_indices_.end(), comp_op);
506 std::vector<data_size_t> feature_sort_indices_;
507 int32_t feature_index_;
514 num_features_ = covariates.cols();
515 feature_presort_.resize(num_features_);
516 for (
int i = 0; i < num_features_; i++) {
523 FeaturePresortRoot* GetFeaturePresort(
int feature_num) {
return feature_presort_[feature_num].get(); }
526 std::vector<std::unique_ptr<FeaturePresortRoot>> feature_presort_;
544 feature_index_ = feature_index;
545 feature_type_ = feature_type;
546 num_obs_ = covariates.rows();
550 data_size_t node_offset = 0;
551 node_offset_sizes_.emplace_back(node_offset, num_obs_);
560 void SplitFeatureNumeric(Eigen::MatrixXd& covariates, int32_t node_id, int32_t feature_index,
double split_value);
563 void SplitFeatureCategorical(Eigen::MatrixXd& covariates, int32_t node_id, int32_t feature_index, std::vector<std::uint32_t>
const& category_list);
566 data_size_t
NodeBegin(int32_t node_id) {
return node_offset_sizes_[node_id].Begin();}
569 data_size_t
NodeEnd(int32_t node_id) {
return node_offset_sizes_[node_id].End();}
572 data_size_t
NodeSize(int32_t node_id) {
return node_offset_sizes_[node_id].Size();}
590 void AddLeftRightNodes(data_size_t left_node_begin, data_size_t left_node_size, data_size_t right_node_begin, data_size_t right_node_size);
593 std::vector<NodeOffsetSize> node_offset_sizes_;
594 int32_t feature_index_;
595 FeatureType feature_type_;
596 data_size_t num_obs_;
603 num_features_ = covariates.cols();
604 feature_partitions_.resize(num_features_);
606 for (
int i = 0; i < num_features_; i++) {
607 feature_presort_root = feature_presort_root_container->GetFeaturePresort(i);
608 feature_partitions_[i].reset(
new FeaturePresortPartition(feature_presort_root, covariates, i, feature_types[i]));
613 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int feature_split,
TreeSplit& split,
int num_threads = -1) {
614 StochTree::ParallelFor(0, num_features_, num_threads, [&](
int i) {
615 feature_partitions_[i]->SplitFeature(covariates, node_id, feature_split, split);
620 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int feature_split,
double split_value,
int num_threads = -1) {
621 StochTree::ParallelFor(0, num_features_, num_threads, [&](
int i) {
622 feature_partitions_[i]->SplitFeatureNumeric(covariates, node_id, feature_split, split_value);
627 void PartitionNode(Eigen::MatrixXd& covariates,
int node_id,
int feature_split, std::vector<std::uint32_t>
const& category_list,
int num_threads = -1) {
628 StochTree::ParallelFor(0, num_features_, num_threads, [&](
int i) {
629 feature_partitions_[i]->SplitFeatureCategorical(covariates, node_id, feature_split, category_list);
635 return feature_partitions_[feature_index]->NodeBegin(node_id);
639 data_size_t
NodeEnd(
int node_id,
int feature_index) {
640 return feature_partitions_[feature_index]->NodeEnd(node_id);
644 data_size_t
NodeSize(
int node_id,
int feature_index) {
645 return feature_partitions_[feature_index]->NodeSize(node_id);
648 std::vector<data_size_t>::iterator NodeBeginIterator(
int node_id,
int feature_index) {
649 data_size_t node_begin =
NodeBegin(node_id, feature_index);
650 auto begin_iter = feature_partitions_[feature_index]->feature_sort_indices_.begin();
651 return begin_iter + node_begin;
654 std::vector<data_size_t>::iterator NodeEndIterator(
int node_id,
int feature_index) {
655 data_size_t node_end =
NodeEnd(node_id, feature_index);
656 auto begin_iter = feature_partitions_[feature_index]->feature_sort_indices_.begin();
657 return begin_iter + node_end;
661 std::vector<data_size_t>
NodeIndices(
int node_id,
int feature_index) {
662 return feature_partitions_[feature_index]->NodeIndices(node_id);
666 data_size_t
SortIndex(data_size_t j,
int feature_index) {
return feature_partitions_[feature_index]->SortIndex(j); }
670 feature_partitions_[feature_index]->UpdateObservationMapping(node_id, tree_id, sample_node_mapper);
674 std::vector<std::unique_ptr<FeaturePresortPartition>> feature_partitions_;
Internal wrapper around Eigen::VectorXd interface for univariate floating point data....
Definition data.h:193
Data structure that tracks pre-sorted feature values through a tree's split lifecycle.
Definition partition_tracker.h:540
void SplitFeature(Eigen::MatrixXd &covariates, int32_t node_id, int32_t feature_index, TreeSplit &split)
Split numeric / ordered categorical feature and update sort indices.
data_size_t NodeEnd(int32_t node_id)
End position of node indexed by node_id.
Definition partition_tracker.h:569
std::vector< data_size_t > NodeIndices(int node_id)
Data indices for a given node.
std::vector< data_size_t > feature_sort_indices_
Feature sort indices.
Definition partition_tracker.h:587
data_size_t NodeSize(int32_t node_id)
Size (in observations) of node indexed by node_id.
Definition partition_tracker.h:572
FeatureType GetFeatureType()
Feature type.
Definition partition_tracker.h:581
data_size_t SortIndex(data_size_t j)
Feature sort index j.
Definition partition_tracker.h:578
data_size_t NodeBegin(int32_t node_id)
Start position of node indexed by node_id.
Definition partition_tracker.h:566
void UpdateObservationMapping(int node_id, int tree_id, SampleNodeMapper *sample_node_mapper)
Update SampleNodeMapper for all the observations in node_id.
void SplitFeatureNumeric(Eigen::MatrixXd &covariates, int32_t node_id, int32_t feature_index, double split_value)
Split numeric / ordered categorical feature and update sort indices.
void SplitFeatureCategorical(Eigen::MatrixXd &covariates, int32_t node_id, int32_t feature_index, std::vector< std::uint32_t > const &category_list)
Split unordered categorical feature and update sort indices.
Container class for FeaturePresortRoot objects stored for every feature in a dataset.
Definition partition_tracker.h:511
Data structure for presorting a feature by its values.
Definition partition_tracker.h:479
Mapping nodes to the indices they contain.
Definition partition_tracker.h:235
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int left_node_id, int right_node_id, int feature_split, double split_value)
Partition a node based on a new split rule.
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int left_node_id, int right_node_id, int feature_split, TreeSplit &split)
Partition a node based on a new split rule.
int RightNode(int node_id)
Right child of node_id.
int Parent(int node_id)
Parent node_id.
data_size_t NodeEnd(int node_id)
One past the last index of data points contained in node_id.
std::vector< data_size_t > indices_
Data indices.
Definition partition_tracker.h:285
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int left_node_id, int right_node_id, int feature_split, std::vector< std::uint32_t > const &category_list)
Partition a node based on a new split rule.
bool RightNodeIsLeaf(int node_id)
Whether node_id's right child is a leaf.
void UpdateObservationMapping(int node_id, int tree_id, SampleNodeMapper *sample_node_mapper)
Update SampleNodeMapper for all the observations in node_id.
data_size_t NodeSize(int node_id)
Number of data points contained in node_id.
std::vector< data_size_t > NodeIndices(int node_id)
Data indices for a given node.
void ReconstituteFromTree(Tree &tree, ForestDataset &dataset)
Reconstitute a tree partition tracker from root based on a tree.
bool IsLeaf(int node_id)
Whether node_id is a leaf.
void PruneNodeToLeaf(int node_id)
Convert a (currently split) node to a leaf.
bool LeftNodeIsLeaf(int node_id)
Whether node_id's left child is a leaf.
int LeftNode(int node_id)
Left child of node_id.
bool IsValidNode(int node_id)
Whether node_id is a valid node.
data_size_t NodeBegin(int node_id)
First index of data points contained in node_id.
API for loading and accessing data used to sample tree ensembles The covariates / bases / weights use...
Definition data.h:271
"Superclass" wrapper around tracking data structures for forest sampling algorithms
Definition partition_tracker.h:46
ForestTracker(Eigen::MatrixXd &covariates, std::vector< FeatureType > &feature_types, int num_trees, int num_observations)
Construct a new ForestTracker object.
Tracking cutpoints available at a given node.
Definition partition_tracker.h:442
Class storing sample-node map for each tree in an ensemble.
Definition partition_tracker.h:166
Class storing sample-prediction map for each tree in an ensemble.
Definition partition_tracker.h:125
Data structure for tracking observations through a tree partition with each feature pre-sorted.
Definition partition_tracker.h:600
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int feature_split, TreeSplit &split, int num_threads=-1)
Partition a node based on a new split rule.
Definition partition_tracker.h:613
data_size_t NodeSize(int node_id, int feature_index)
One past the last index of data points contained in node_id.
Definition partition_tracker.h:644
void UpdateObservationMapping(int node_id, int tree_id, SampleNodeMapper *sample_node_mapper, int feature_index=0)
Update SampleNodeMapper for all the observations in node_id.
Definition partition_tracker.h:669
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int feature_split, double split_value, int num_threads=-1)
Partition a node based on a new split rule.
Definition partition_tracker.h:620
std::vector< data_size_t > NodeIndices(int node_id, int feature_index)
Data indices for a given node.
Definition partition_tracker.h:661
data_size_t SortIndex(data_size_t j, int feature_index)
Feature sort index j for feature_index.
Definition partition_tracker.h:666
data_size_t NodeBegin(int node_id, int feature_index)
First index of data points contained in node_id.
Definition partition_tracker.h:634
void PartitionNode(Eigen::MatrixXd &covariates, int node_id, int feature_split, std::vector< std::uint32_t > const &category_list, int num_threads=-1)
Partition a node based on a new split rule.
Definition partition_tracker.h:627
data_size_t NodeEnd(int node_id, int feature_index)
One past the last index of data points contained in node_id.
Definition partition_tracker.h:639
Class storing a "forest," or an ensemble of decision trees.
Definition ensemble.h:31
Representation of arbitrary tree split rules, including numeric split rules (X[,i] <= c) and categori...
Definition tree.h:958
bool SplitTrue(double fvalue)
Whether a given covariate value is True or False on the rule defined by a TreeSplit object.
Definition tree.h:990
Decision tree data structure.
Definition tree.h:66
std::vector< std::int32_t > const & GetLeaves() const
Get indices of all leaf nodes.
Definition tree.h:564
Mapping nodes to the indices they contain.
Definition partition_tracker.h:309
void PartitionTreeNode(Eigen::MatrixXd &covariates, int tree_id, int node_id, int left_node_id, int right_node_id, int feature_split, std::vector< std::uint32_t > const &category_list)
Partition a node based on a new split rule.
Definition partition_tracker.h:333
void UpdateObservationMapping(Tree *tree, int tree_id, SampleNodeMapper *sample_node_mapper)
Update SampleNodeMapper for all the observations in tree.
Definition partition_tracker.h:420
int RightNode(int tree_id, int node_id)
Right child of node_id.
Definition partition_tracker.h:405
bool IsLeaf(int tree_id, int node_id)
Whether node_id is a leaf.
Definition partition_tracker.h:348
bool RightNodeIsLeaf(int tree_id, int node_id)
Whether node_id's right child is a leaf.
Definition partition_tracker.h:363
bool IsValidNode(int tree_id, int node_id)
Whether node_id is a valid node.
Definition partition_tracker.h:353
void UpdateObservationMapping(int node_id, int tree_id, SampleNodeMapper *sample_node_mapper)
Update SampleNodeMapper for all the observations in node_id.
Definition partition_tracker.h:415
data_size_t NodeBegin(int tree_id, int node_id)
First index of data points contained in node_id.
Definition partition_tracker.h:368
int NumTrees()
Number of trees.
Definition partition_tracker.h:430
int LeftNode(int tree_id, int node_id)
Left child of node_id.
Definition partition_tracker.h:400
void ResetTreeToRoot(int tree_id, data_size_t n)
Convert a tree to root.
Definition partition_tracker.h:338
void PartitionTreeNode(Eigen::MatrixXd &covariates, int tree_id, int node_id, int left_node_id, int right_node_id, int feature_split, TreeSplit &split)
Partition a node based on a new split rule.
Definition partition_tracker.h:323
data_size_t NodeSize(int tree_id, int node_id)
One past the last index of data points contained in node_id.
Definition partition_tracker.h:390
bool LeftNodeIsLeaf(int tree_id, int node_id)
Whether node_id's left child is a leaf.
Definition partition_tracker.h:358
int Parent(int tree_id, int node_id)
Parent node_id.
Definition partition_tracker.h:395
void ReconstituteFromForest(TreeEnsemble &forest, ForestDataset &dataset)
Reconstruct the node sample tracker based on the splits in a forest.
data_size_t NodeEnd(int tree_id, int node_id)
One past the last index of data points contained in node_id.
Definition partition_tracker.h:373
void PartitionTreeNode(Eigen::MatrixXd &covariates, int tree_id, int node_id, int left_node_id, int right_node_id, int feature_split, double split_value)
Partition a node based on a new split rule.
Definition partition_tracker.h:328
FeatureUnsortedPartition * GetFeaturePartition(int i)
Return a pointer to the feature partition tracking tree i.
Definition partition_tracker.h:433
std::vector< data_size_t > TreeNodeIndices(int tree_id, int node_id)
Data indices for a given node.
Definition partition_tracker.h:410
void PruneTreeNodeToLeaf(int tree_id, int node_id)
Convert a (currently split) node to a leaf.
Definition partition_tracker.h:343
A collection of random number generation utilities.
Definition category_tracker.h:36