ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Tree.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "utils/Types.hpp"
4
5#include "models/Bagged.hpp"
6#include "models/Model.hpp"
7#include "models/TreeNode.hpp"
8
9
10namespace ppforest2 {
29 class Tree : public Model {
30 public:
31 using Ptr = std::unique_ptr<Tree>;
32 using Model::predict;
33
38 using RNG = stats::RNG;
39
41
43
46
72
75
76
85
87 void accept(Model::Visitor& visitor) const override = 0;
88
89 bool operator==(Tree const& other) const;
90 bool operator!=(Tree const& other) const;
91
92 protected:
94 : root(std::move(root)) {
95 training_spec = std::move(spec);
96 degenerate = this->root && this->root->degenerate;
97 }
98
120 static Root
121 build_root(TrainingSpec const& spec, FeatureMatrix& x, OutcomeVector& y, GroupPartition const& y_part, RNG& rng);
122 };
123
130}
Visitor interface for model dispatch.
Definition Model.hpp:51
Abstract base class for predictive models (trees and forests).
Definition Model.hpp:29
bool degenerate
Whether the model contains degenerate nodes/splits.
Definition Model.hpp:67
virtual types::Outcome predict(types::FeatureVector const &x) const =0
Predict a single observation.
TrainingSpec::Ptr training_spec
Training specification used to build this model.
Definition Model.hpp:70
Training configuration for projection pursuit trees and forests.
Definition TrainingSpec.hpp:43
std::shared_ptr< TrainingSpec > Ptr
Definition TrainingSpec.hpp:45
std::unique_ptr< TreeNode > Ptr
Definition TreeNode.hpp:21
types::OutcomeVector OutcomeVector
Definition Tree.hpp:36
static Ptr train(TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y)
Train a tree from a response vector.
bool operator==(Tree const &other) const
bool operator!=(Tree const &other) const
Root root
Root node of the tree.
Definition Tree.hpp:45
TreeNode::Ptr Root
Definition Tree.hpp:40
void accept(Model::Visitor &visitor) const override=0
Accept a model visitor (mode-specific dispatch).
stats::RNG RNG
Definition Tree.hpp:38
static Root build_root(TrainingSpec const &spec, FeatureMatrix &x, OutcomeVector &y, GroupPartition const &y_part, RNG &rng)
Build the root node of a tree.
Tree(TreeNode::Ptr root, TrainingSpec::Ptr spec)
Definition Tree.hpp:93
std::unique_ptr< Tree > Ptr
Definition Tree.hpp:31
types::Outcome Outcome
Definition Tree.hpp:37
types::FeatureMatrix FeatureMatrix
Definition Tree.hpp:34
stats::GroupPartition GroupPartition
Definition Tree.hpp:42
static Ptr train(TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y, stats::RNG &rng)
Train a tree from a response vector.
types::Outcome predict(types::FeatureVector const &x) const override
Predict a single observation.
types::FeatureVector FeatureVector
Definition Tree.hpp:35
Contiguous-block representation of grouped observations.
Definition GroupPartition.hpp:40
pcg32 RNG
Definition Stats.hpp:24
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:33
Eigen::Matrix< Outcome, Eigen::Dynamic, 1 > OutcomeVector
Dynamic-size column vector of predictions.
Definition Types.hpp:42
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:36
Feature Outcome
Scalar type for predictions (float for both classification and regression).
Definition Types.hpp:30
Binarization strategies for multiclass-to-binary reduction.
Definition Benchmark.hpp:25
Bagged< Tree > BaggedTree
Alias for the dominant Bagged instantiation in this codebase — a bootstrap-aggregated Tree....
Definition Tree.hpp:129
Bootstrap-aggregated model wrapper.
Definition Bagged.hpp:32