|
ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
|
Random forest of classification trees. More...
#include <ClassificationForest.hpp>
Public Types | |
| using | FeatureMatrix = types::FeatureMatrix |
| using | FeatureVector = types::FeatureVector |
| using | GroupIndices = std::map<types::GroupId, int> |
| using | GroupPartition = stats::GroupPartition |
| using | Groups = std::set<types::GroupId> |
| using | Outcome = types::Outcome |
| using | OutcomeVector = types::OutcomeVector |
| using | Ptr = std::unique_ptr<ClassificationForest> |
| using | RNG = stats::RNG |
Public Types inherited from ppforest2::Forest | |
| using | FeatureMatrix = types::FeatureMatrix |
| using | FeatureVector = types::FeatureVector |
| using | Outcome = types::Outcome |
| using | OutcomeVector = types::OutcomeVector |
| using | Ptr = std::unique_ptr<Forest> |
| using | RNG = stats::RNG |
Public Types inherited from ppforest2::Model | |
| using | Ptr = std::shared_ptr<Model> |
Public Member Functions | |
| ClassificationForest (TrainingSpec::Ptr spec, Groups groups) | |
| void | accept (Model::Visitor &visitor) const override |
| Accept a model visitor (mode-specific dispatch). | |
| FeatureMatrix | predict (FeatureMatrix const &x, Proportions) const |
Vote proportions per row, columns laid out by groups. | |
| FeatureMatrix | predict (FeatureMatrix const &x, Proportions, GroupIndices const &indices) const |
| Vote proportions per row, with an explicit column layout. | |
| types::Outcome | predict (FeatureVector const &x) const override |
| Per-row prediction (mode-specific: majority vote or mean). | |
| FeatureVector | predict (FeatureVector const &x, Proportions) const |
Vote proportions for one observation, columns laid out by groups. | |
| FeatureVector | predict (FeatureVector const &x, Proportions, GroupIndices const &indices) const |
Vote proportions for one observation, with an explicit column layout passed as a precomputed {group → column} map. | |
Public Member Functions inherited from ppforest2::Forest | |
| void | add_tree (BaggedTree::Ptr tree) |
| Add a trained bagged tree to the forest. | |
| bool | operator!= (Forest const &other) const |
| bool | operator== (Forest const &other) const |
| virtual types::OutcomeVector | predict (types::FeatureMatrix const &x) const |
| Predict a matrix of observations. | |
Public Member Functions inherited from ppforest2::Model | |
| virtual | ~Model ()=default |
Static Public Member Functions | |
| static Ptr | train (TrainingSpec const &spec, FeatureMatrix const &x, OutcomeVector const &y) |
Static Public Member Functions inherited from ppforest2::Forest | |
| static Ptr | train (TrainingSpec const &spec, FeatureMatrix const &x, OutcomeVector const &y) |
| Train a random forest. | |
Static Public Member Functions inherited from ppforest2::Model | |
| static void | check_train_inputs (types::FeatureMatrix const &x, types::OutcomeVector const &y) |
| Validate common training inputs (y non-empty, matching x rows). | |
| static Ptr | train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y) |
| Train a model from a training specification. | |
Public Attributes | |
| Groups | groups |
| Set of group labels this forest predicts over. | |
Public Attributes inherited from ppforest2::Forest | |
| std::vector< BaggedTree::Ptr > | trees |
Bootstrap-aggregated trees. Each BaggedTree pairs the polymorphic inner Tree with its sample indices. | |
Public Attributes inherited from ppforest2::Model | |
| bool | degenerate = false |
| Whether the model contains degenerate nodes/splits. | |
| TrainingSpec::Ptr | training_spec |
| Training specification used to build this model. | |
Protected Member Functions | |
| BaggedTree::Ptr | train_tree (FeatureMatrix const &x, OutcomeVector const &y, RNG &rng) const override |
Train one bagged tree on a bootstrap resample of x / y. | |
Protected Member Functions inherited from ppforest2::Forest | |
| Forest ()=default | |
| Forest (TrainingSpec::Ptr spec) | |
| void | build_trees (types::FeatureMatrix const &x, types::OutcomeVector const &y) |
Build training_spec->size bagged trees in parallel and attach them to this forest. | |
Random forest of classification trees.
Aggregates per-tree predictions by majority vote. Use the free functions in Metrics.hpp for OOB diagnostics and variable importance, and predict_proportions (in Model.hpp) for per-group vote proportions.
| using ppforest2::ClassificationForest::GroupIndices = std::map<types::GroupId, int> |
| using ppforest2::ClassificationForest::Groups = std::set<types::GroupId> |
| using ppforest2::ClassificationForest::Ptr = std::unique_ptr<ClassificationForest> |
|
inline |
|
overridevirtual |
Accept a model visitor (mode-specific dispatch).
Implements ppforest2::Forest.
| FeatureMatrix ppforest2::ClassificationForest::predict | ( | FeatureMatrix const & | x, |
| Proportions | ) const |
Vote proportions per row, columns laid out by groups.
| FeatureMatrix ppforest2::ClassificationForest::predict | ( | FeatureMatrix const & | x, |
| Proportions | , | ||
| GroupIndices const & | indices ) const |
Vote proportions per row, with an explicit column layout.
Iterates rows and calls the single-row predict(..., indices) overload — indices is built zero times here.
|
overridevirtual |
Per-row prediction (mode-specific: majority vote or mean).
Implements ppforest2::Forest.
| FeatureVector ppforest2::ClassificationForest::predict | ( | FeatureVector const & | x, |
| Proportions | ) const |
Vote proportions for one observation, columns laid out by groups.
| FeatureVector ppforest2::ClassificationForest::predict | ( | FeatureVector const & | x, |
| Proportions | , | ||
| GroupIndices const & | indices ) const |
Vote proportions for one observation, with an explicit column layout passed as a precomputed {group → column} map.
Base primitive. The matrix overload calls this once per row with the same indices, so the map is built only once per predict(matrix, ...) call rather than n times.
|
static |
|
overrideprotectedvirtual |
Train one bagged tree on a bootstrap resample of x / y.
Mode-specific hook invoked by build_trees once per slot in the forest (with retries on degenerate trees). Subclasses that need per-training shared state (e.g. ClassificationForest caches the parent's label partition for stratified sampling) hold it as a private transient pointer set up before build_trees runs.
Called from inside build_trees's OpenMP parallel for, so implementations must be thread-safe and read-only over *this.
Implements ppforest2::Forest.
| Groups ppforest2::ClassificationForest::groups |
Set of group labels this forest predicts over.
Canonical column layout for predict(FeatureMatrix, Proportions). Populated at construction (training: from y_part.groups; JSON: from meta.groups indices; R: from forest$groups names). Independent of any individual tree's node_groups() — a degenerate-retry tree with a narrower group set can't shrink the prediction matrix.