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

Random forest of regression trees. More...

#include <RegressionForest.hpp>

Public Types

using FeatureMatrix = types::FeatureMatrix
 
using FeatureVector = types::FeatureVector
 
using Outcome = types::Outcome
 
using OutcomeVector = types::OutcomeVector
 
using Ptr = std::unique_ptr<RegressionForest>
 
- 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

 RegressionForest ()
 
 RegressionForest (TrainingSpec::Ptr spec)
 
void accept (Model::Visitor &visitor) const override
 Accept a model visitor (mode-specific dispatch).
 
types::Outcome predict (FeatureVector const &x) const override
 Per-row prediction (mode-specific: majority vote or mean).
 
virtual types::OutcomeVector predict (types::FeatureMatrix const &x) const
 Predict a matrix of observations.
 
- 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
 
- 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.
 

Protected Member Functions

BaggedTree::Ptr train_tree (FeatureMatrix const &x, OutcomeVector const &y, stats::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.
 

Additional Inherited Members

- Public Attributes inherited from ppforest2::Forest
std::vector< BaggedTree::Ptrtrees
 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.
 

Detailed Description

Random forest of regression trees.

Aggregates per-tree predictions by arithmetic mean. Use the free functions in Metrics.hpp for OOB diagnostics and variable importance.

Member Typedef Documentation

◆ FeatureMatrix

◆ FeatureVector

◆ Outcome

◆ OutcomeVector

◆ Ptr

Constructor & Destructor Documentation

◆ RegressionForest() [1/2]

ppforest2::RegressionForest::RegressionForest ( )

◆ RegressionForest() [2/2]

ppforest2::RegressionForest::RegressionForest ( TrainingSpec::Ptr spec)
explicit

Member Function Documentation

◆ accept()

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

Accept a model visitor (mode-specific dispatch).

Implements ppforest2::Forest.

◆ predict() [1/2]

types::Outcome ppforest2::RegressionForest::predict ( FeatureVector const & x) const
overridevirtual

Per-row prediction (mode-specific: majority vote or mean).

Implements ppforest2::Forest.

◆ predict() [2/2]

virtual types::OutcomeVector ppforest2::Model::predict ( types::FeatureMatrix const & x) const
inlinevirtual

Predict a matrix of observations.

Default implementation iterates rows and dispatches to the single-row predict. Subclasses may override to vectorize.

Parameters
xFeature matrix (n × p).
Returns
Predicted group labels (n).

Reimplemented from ppforest2::Forest.

◆ train()

static Ptr ppforest2::RegressionForest::train ( TrainingSpec const & spec,
FeatureMatrix const & x,
OutcomeVector const & y )
static

◆ train_tree()

BaggedTree::Ptr ppforest2::RegressionForest::train_tree ( FeatureMatrix const & x,
OutcomeVector const & y,
stats::RNG & rng ) const
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.


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