ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::Forest Struct Reference

A projection pursuit random forest. More...

#include <Forest.hpp>

Public Member Functions

 Forest ()
 
 Forest (TrainingSpec::Ptr training_spec)
 
void accept (Model::Visitor &visitor) const override
 Accept a model visitor (double dispatch).
 
void add_tree (std::unique_ptr< BootstrapTree > tree)
 Add a tree to the forest.
 
double oob_error (types::FeatureMatrix const &x, types::ResponseVector const &y) const
 Out-of-bag error rate.
 
types::ResponseVector oob_predict (types::FeatureMatrix const &x) const
 Out-of-bag predictions by majority vote.
 
bool operator!= (Forest const &other) const
 
bool operator== (Forest const &other) const
 
types::ResponseVector predict (types::FeatureMatrix const &data) const override
 Predict a matrix of observations.
 
types::FeatureMatrix predict (types::FeatureMatrix const &data, Proportions) const override
 Predict vote proportions for a matrix of observations.
 
types::Response predict (types::FeatureVector const &data) const override
 Predict a single observation.
 
- Public Member Functions inherited from ppforest2::Model
virtual ~Model ()=default
 

Static Public Member Functions

static Forest train (TrainingSpec const &training_spec, types::FeatureMatrix const &x, types::ResponseVector const &y)
 Train a random forest.
 
- Static Public Member Functions inherited from ppforest2::Model
static Ptr train (TrainingSpec const &spec, types::FeatureMatrix const &x, types::ResponseVector const &y)
 Train a model from a training specification.
 

Public Attributes

std::vector< BootstrapTree::Ptrtrees
 
- 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.
 

Additional Inherited Members

- Public Types inherited from ppforest2::Model
using Ptr = std::shared_ptr<Model>
 

Detailed Description

A projection pursuit random forest.

An ensemble of BootstrapTree instances, each trained on a bootstrap sample. Predictions are made by majority vote. Out-of-bag estimation and vote-proportion predictions are supported.

Forest forest = Forest::train(spec, x, y);
types::ResponseVector preds = forest.predict(x_test);
double oob = forest.oob_error(x, y);
// Vote proportions — (n × G) matrix, rows sum to 1.
types::FeatureMatrix probs = forest.predict(x_test, Proportions{});
DRStrategy::Ptr uniform(int n_vars)
Factory function for a uniform DR strategy.
PPStrategy::Ptr pda(float lambda)
Factory function for a PDA projection pursuit strategy.
SRStrategy::Ptr mean_of_means()
Factory function for a mean-of-means split strategy.
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:24
Eigen::Matrix< Response, Eigen::Dynamic, 1 > ResponseVector
Dynamic-size column vector of group labels.
Definition Types.hpp:29
static Forest train(TrainingSpec const &training_spec, types::FeatureMatrix const &x, types::ResponseVector const &y)
Train a random forest.
double oob_error(types::FeatureMatrix const &x, types::ResponseVector const &y) const
Out-of-bag error rate.
types::Response predict(types::FeatureVector const &data) const override
Predict a single observation.
Tag type for requesting vote-proportion predictions.
Definition Model.hpp:19
Training configuration for projection pursuit trees and forests.
Definition TrainingSpec.hpp:40

Constructor & Destructor Documentation

◆ Forest() [1/2]

ppforest2::Forest::Forest ( )

◆ Forest() [2/2]

ppforest2::Forest::Forest ( TrainingSpec::Ptr training_spec)
explicit

Member Function Documentation

◆ accept()

void ppforest2::Forest::accept ( Model::Visitor & visitor) const
overridevirtual

Accept a model visitor (double dispatch).

Implements ppforest2::Model.

◆ add_tree()

void ppforest2::Forest::add_tree ( std::unique_ptr< BootstrapTree > tree)

Add a tree to the forest.

Parameters
treeTree to add (ownership transferred).

◆ oob_error()

double ppforest2::Forest::oob_error ( types::FeatureMatrix const & x,
types::ResponseVector const & y ) const

Out-of-bag error rate.

For each observation, predicts using majority vote of only the trees where it was out-of-bag, then computes the overall misclassification rate.

Parameters
xTraining feature matrix (n × p).
yTraining response vector (n).
Returns
Error rate in [0, 1], or −1 if no observation has any OOB tree.

◆ oob_predict()

types::ResponseVector ppforest2::Forest::oob_predict ( types::FeatureMatrix const & x) const

Out-of-bag predictions by majority vote.

For each observation, predicts using majority vote of only the trees where it was out-of-bag. Observations with no OOB tree receive a sentinel value (−1) and are excluded when computing oob_error().

Parameters
xTraining feature matrix (n × p).
Returns
OOB predictions (n); −1 where no OOB tree exists.

◆ operator!=()

bool ppforest2::Forest::operator!= ( Forest const & other) const

◆ operator==()

bool ppforest2::Forest::operator== ( Forest const & other) const

◆ predict() [1/3]

types::ResponseVector ppforest2::Forest::predict ( types::FeatureMatrix const & data) const
overridevirtual

Predict a matrix of observations.

Parameters
dataFeature matrix (n × p).
Returns
Predictions (n).

Implements ppforest2::Model.

◆ predict() [2/3]

types::FeatureMatrix ppforest2::Forest::predict ( types::FeatureMatrix const & data,
Proportions  ) const
overridevirtual

Predict vote proportions for a matrix of observations.

For each observation, counts votes from every tree and returns the proportion of trees that voted for each group. The number of groups G is derived from the root node of the first tree.

Parameters
dataFeature matrix (n × p).
Returns
Vote proportions matrix (n × G), rows sum to 1.0.

Implements ppforest2::Model.

◆ predict() [3/3]

types::Response ppforest2::Forest::predict ( types::FeatureVector const & data) const
overridevirtual

Predict a single observation.

Parameters
dataFeature vector (p).
Returns
Prediction.

Implements ppforest2::Model.

◆ train()

static Forest ppforest2::Forest::train ( TrainingSpec const & training_spec,
types::FeatureMatrix const & x,
types::ResponseVector const & y )
static

Train a random forest.

Forest-level parameters (size, seed, threads, max_retries) are read from the training specification.

Parameters
training_specTraining specification.
xFeature matrix (n × p).
yResponse vector (n).
Returns
Trained forest.

Member Data Documentation

◆ trees

std::vector<BootstrapTree::Ptr> ppforest2::Forest::trees

The documentation for this struct was generated from the following file: