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

#include <BootstrapTree.hpp>

Public Types

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

Public Member Functions

 BootstrapTree (TreeNode::Ptr root, TrainingSpec::Ptr spec, std::vector< int > samp)
 
std::vector< int > oob_indices (int n_total) const
 Indices of observations not in the bootstrap sample.
 
types::ResponseVector predict_oob (types::FeatureMatrix const &x, std::vector< int > const &row_idx) const
 Predict for a subset of rows (e.g. OOB indices).
 
 Tree (TreeNode::Ptr root, TrainingSpec::Ptr training_spec)
 
- Public Member Functions inherited from ppforest2::Tree
 Tree (TreeNode::Ptr root, TrainingSpec::Ptr training_spec)
 
void accept (Model::Visitor &visitor) const override
 Accept a model visitor (double dispatch).
 
bool operator!= (Tree const &other) const
 
bool operator== (Tree 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 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 Ptr train (TrainingSpec::Ptr const &training_spec, types::FeatureMatrix const &x, stats::GroupPartition const &group_spec, stats::RNG &rng)
 Train a bootstrap tree.
 
- Static Public Member Functions inherited from ppforest2::Tree
static Tree train (TrainingSpec const &training_spec, types::FeatureMatrix const &x, stats::GroupPartition const &group_spec, stats::RNG &rng)
 Train a tree from a group partition.
 
static Tree train (TrainingSpec const &training_spec, types::FeatureMatrix const &x, types::ResponseVector const &y, stats::RNG &rng)
 Train a tree from a response vector.
 
- 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< int > sample_indices
 
- Public Attributes inherited from ppforest2::Tree
TreeNode::Ptr 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.
 

Member Typedef Documentation

◆ Ptr

using ppforest2::BootstrapTree::Ptr = std::unique_ptr<BootstrapTree>

Constructor & Destructor Documentation

◆ BootstrapTree()

ppforest2::BootstrapTree::BootstrapTree ( TreeNode::Ptr root,
TrainingSpec::Ptr spec,
std::vector< int > samp )

Member Function Documentation

◆ oob_indices()

std::vector< int > ppforest2::BootstrapTree::oob_indices ( int n_total) const

Indices of observations not in the bootstrap sample.

Parameters
n_totalTotal number of observations in the training set.
Returns
Sorted vector of out-of-bag row indices.

◆ predict_oob()

types::ResponseVector ppforest2::BootstrapTree::predict_oob ( types::FeatureMatrix const & x,
std::vector< int > const & row_idx ) const

Predict for a subset of rows (e.g. OOB indices).

Typically used with oob_indices() to obtain predictions for out-of-bag observations only. The returned vector has the same size as row_idx; element i is the prediction for row row_idx[i].

Parameters
xFeature matrix (n × p).
row_idxRow indices to predict.
Returns
Predictions for each row in row_idx.

◆ train()

static Ptr ppforest2::BootstrapTree::train ( TrainingSpec::Ptr const & training_spec,
types::FeatureMatrix const & x,
stats::GroupPartition const & group_spec,
stats::RNG & rng )
static

Train a bootstrap tree.

Samples rows from x according to group_spec, trains a tree on the sampled data, and stores the sample indices for OOB queries.

Parameters
training_specTraining specification (shared).
xFeature matrix (n × p).
group_specGroup partition for stratified sampling.
rngRandom number generator.
Returns
Trained bootstrap tree.

◆ Tree()

ppforest2::Tree::Tree ( TreeNode::Ptr root,
TrainingSpec::Ptr training_spec )

Member Data Documentation

◆ sample_indices

std::vector<int> ppforest2::BootstrapTree::sample_indices

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