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

Abstract base class for predictive models (trees and forests). More...

#include <Model.hpp>

Classes

class  Visitor
 Visitor interface for model dispatch. More...
 

Public Types

using Ptr = std::shared_ptr<Model>
 

Public Member Functions

virtual ~Model ()=default
 
virtual void accept (Visitor &visitor) const =0
 Accept a model visitor (double dispatch).
 
virtual types::OutcomeVector predict (types::FeatureMatrix const &x) const
 Predict a matrix of observations.
 
virtual types::Outcome predict (types::FeatureVector const &x) const =0
 Predict a single observation.
 

Static Public Member Functions

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

bool degenerate = false
 Whether the model contains degenerate nodes/splits.
 
TrainingSpec::Ptr training_spec
 Training specification used to build this model.
 

Detailed Description

Abstract base class for predictive models (trees and forests).

Member Typedef Documentation

◆ Ptr

using ppforest2::Model::Ptr = std::shared_ptr<Model>

Constructor & Destructor Documentation

◆ ~Model()

virtual ppforest2::Model::~Model ( )
virtualdefault

Member Function Documentation

◆ accept()

virtual void ppforest2::Model::accept ( Visitor & visitor) const
pure virtual

◆ check_train_inputs()

static void ppforest2::Model::check_train_inputs ( types::FeatureMatrix const & x,
types::OutcomeVector const & y )
static

Validate common training inputs (y non-empty, matching x rows).

Throws UserError on failure. Called by Tree::train and Forest::train at their entry points so both modes get the same validation and the checks aren't duplicated per-mode.

◆ predict() [1/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 in ppforest2::Forest, ppforest2::RegressionForest, and ppforest2::Tree.

◆ predict() [2/2]

virtual types::Outcome ppforest2::Model::predict ( types::FeatureVector const & x) const
pure virtual

Predict a single observation.

Parameters
xFeature vector (p).
Returns
Predicted group label.

Implemented in ppforest2::ClassificationForest, ppforest2::ClassificationTree, ppforest2::Forest, ppforest2::RegressionForest, ppforest2::RegressionTree, and ppforest2::Tree.

◆ train()

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

Train a model from a training specification.

Dispatches to Tree::train or Forest::train based on spec.is_forest().

Parameters
specTraining specification.
xFeature matrix (n × p).
yOutcome vector (n).
Returns
Trained model (Tree or Forest).

Member Data Documentation

◆ degenerate

bool ppforest2::Model::degenerate = false

Whether the model contains degenerate nodes/splits.

◆ training_spec

TrainingSpec::Ptr ppforest2::Model::training_spec

Training specification used to build this model.


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