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

A projection pursuit decision tree for classification. More...

#include <ClassificationTree.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<ClassificationTree>
 
using RNG = stats::RNG
 
- Public Types inherited from ppforest2::Tree
using FeatureMatrix = types::FeatureMatrix
 
using FeatureVector = types::FeatureVector
 
using GroupPartition = stats::GroupPartition
 
using Outcome = types::Outcome
 
using OutcomeVector = types::OutcomeVector
 
using Ptr = std::unique_ptr<Tree>
 
using RNG = stats::RNG
 
using Root = TreeNode::Ptr
 
- Public Types inherited from ppforest2::Model
using Ptr = std::shared_ptr<Model>
 

Public Member Functions

 ClassificationTree (TreeNode::Ptr root, 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
 One-hot encoding of the predicted group per row, columns laid out by groups().
 
FeatureMatrix predict (FeatureMatrix const &x, Proportions, GroupIndices const &indices) const
 One-hot encoding per row, with an explicit column layout.
 
FeatureVector predict (FeatureVector const &x, Proportions, GroupIndices const &indices) const
 One-hot encoding for one observation, with an explicit column layout passed as a precomputed {group → column} map.
 
types::Outcome predict (types::FeatureVector const &x) const override
 Predict a single observation.
 
types::FeatureVector predict (types::FeatureVector const &x, Proportions) const
 One-hot encoding of the predicted group for one observation, with columns laid out by groups().
 
- Public Member Functions inherited from ppforest2::Tree
bool operator!= (Tree const &other) const
 
bool operator== (Tree const &other) const
 
virtual types::OutcomeVector predict (types::FeatureMatrix const &x) const
 Predict a matrix of observations.
 
types::Outcome predict (types::FeatureVector const &x) const override
 Predict a single observation.
 
- Public Member Functions inherited from ppforest2::Model
virtual ~Model ()=default
 

Static Public Member Functions

static Ptr train (TrainingSpec const &s, FeatureMatrix &x, OutcomeVector &y, GroupPartition const &y_part, RNG &rng)
 Train a classification tree with an external RNG.
 
- Static Public Member Functions inherited from ppforest2::Tree
static Ptr train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y)
 Train a tree from a response vector.
 
static Ptr train (TrainingSpec const &spec, types::FeatureMatrix &x, types::OutcomeVector &y, stats::RNG &rng)
 Train a tree from a response vector.
 
- 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 tree predicts over.
 
- Public Attributes inherited from ppforest2::Tree
Root root
 Root node of the tree.
 
- 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

- Protected Member Functions inherited from ppforest2::Tree
 Tree (TreeNode::Ptr root, TrainingSpec::Ptr spec)
 
- Static Protected Member Functions inherited from ppforest2::Tree
static Root build_root (TrainingSpec const &spec, FeatureMatrix &x, OutcomeVector &y, GroupPartition const &y_part, RNG &rng)
 Build the root node of a tree.
 

Detailed Description

A projection pursuit decision tree for classification.

Leaves hold integer group labels produced by the configured leaf strategy (default MajorityVote). The predict(data, Proportions) overload returns a one-hot encoding of the predicted group.

Member Typedef Documentation

◆ FeatureMatrix

◆ FeatureVector

◆ GroupIndices

◆ GroupPartition

◆ Groups

◆ Outcome

◆ OutcomeVector

◆ Ptr

◆ RNG

Constructor & Destructor Documentation

◆ ClassificationTree()

ppforest2::ClassificationTree::ClassificationTree ( TreeNode::Ptr root,
TrainingSpec::Ptr spec,
Groups groups )
inline

Member Function Documentation

◆ accept()

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

Accept a model visitor (mode-specific dispatch).

Implements ppforest2::Tree.

◆ predict() [1/5]

FeatureMatrix ppforest2::ClassificationTree::predict ( FeatureMatrix const & x,
Proportions  ) const

One-hot encoding of the predicted group per row, columns laid out by groups().

◆ predict() [2/5]

FeatureMatrix ppforest2::ClassificationTree::predict ( FeatureMatrix const & x,
Proportions ,
GroupIndices const & indices ) const

One-hot encoding per row, with an explicit column layout.

Iterates rows calling the single-row predict(..., indices) overload. ClassificationForest::predict(..., Proportions) reuses this so every bagged tree's proportions land in the forest's column layout.

◆ predict() [3/5]

FeatureVector ppforest2::ClassificationTree::predict ( FeatureVector const & x,
Proportions ,
GroupIndices const & indices ) const

One-hot encoding for one observation, with an explicit column layout passed as a precomputed {group → column} map.

Base primitive. indices must contain every label this tree can predict (otherwise at() throws). The matrix overload, and ClassificationForest, both build the indices once at entry and call this overload per row so the map is never rebuilt in a loop.

◆ predict() [4/5]

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

Predict a single observation.

Walks the tree and returns the leaf value. Same implementation for both modes — the leaf value is produced by the mode-specific leaf strategy during training.

Implements ppforest2::Model.

◆ predict() [5/5]

types::FeatureVector ppforest2::ClassificationTree::predict ( types::FeatureVector const & x,
Proportions  ) const

One-hot encoding of the predicted group for one observation, with columns laid out by groups().

◆ train()

static Ptr ppforest2::ClassificationTree::train ( TrainingSpec const & s,
FeatureMatrix & x,
OutcomeVector & y,
GroupPartition const & y_part,
RNG & rng )
static

Train a classification tree with an external RNG.

x and y are non-const for signature symmetry with RegressionTree::train — classification doesn't mutate either.

Parameters
sTraining specification (must have mode = Classification).
xFeature matrix (n × p).
yResponse vector (integer class labels encoded as floats).
y_partInitial root group partition.
rngRandom number generator.

Member Data Documentation

◆ groups

Groups ppforest2::ClassificationTree::groups

Set of group labels this tree predicts over.

Canonical column layout for predict(FeatureMatrix, Proportions). Populated by train (from the parent's y_part.groups) and by the JSON deserializer (from meta.groups). Independent of root->node_groups() so that a stop/leaf combination producing a single-leaf root doesn't shrink the prediction matrix relative to what the model was trained for.


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