ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
Forest.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "models/Model.hpp"
5
6#include <map>
7#include <memory>
8#include <numeric>
9#include <thread>
10#include <vector>
11
12namespace ppforest2 {
32 struct Forest : public Model {
44 static Forest
46
47 std::vector<BootstrapTree::Ptr> trees;
48
51
58 types::Response predict(types::FeatureVector const& data) const override;
59
67
79
85 void add_tree(std::unique_ptr<BootstrapTree> tree);
86
87 bool operator==(Forest const& other) const;
88 bool operator!=(Forest const& other) const;
89
90 void accept(Model::Visitor& visitor) const override;
91
104
117 double oob_error(types::FeatureMatrix const& x, types::ResponseVector const& y) const;
118 };
119}
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:24
Eigen::Matrix< Feature, Eigen::Dynamic, 1 > FeatureVector
Dynamic-size column vector of feature values.
Definition Types.hpp:26
int Response
Scalar type for group labels (integer).
Definition Types.hpp:21
Eigen::Matrix< Response, Eigen::Dynamic, 1 > ResponseVector
Dynamic-size column vector of group labels.
Definition Types.hpp:29
Definition Benchmark.hpp:22
types::ResponseVector predict(types::FeatureMatrix const &data) const override
Predict a matrix of observations.
void add_tree(std::unique_ptr< BootstrapTree > tree)
Add a tree to the forest.
static Forest train(TrainingSpec const &training_spec, types::FeatureMatrix const &x, types::ResponseVector const &y)
Train a random forest.
types::ResponseVector oob_predict(types::FeatureMatrix const &x) const
Out-of-bag predictions by majority vote.
double oob_error(types::FeatureMatrix const &x, types::ResponseVector const &y) const
Out-of-bag error rate.
Forest(TrainingSpec::Ptr training_spec)
bool operator==(Forest const &other) const
types::FeatureMatrix predict(types::FeatureMatrix const &data, Proportions) const override
Predict vote proportions for a matrix of observations.
std::vector< BootstrapTree::Ptr > trees
Definition Forest.hpp:47
void accept(Model::Visitor &visitor) const override
Accept a model visitor (double dispatch).
types::Response predict(types::FeatureVector const &data) const override
Predict a single observation.
bool operator!=(Forest const &other) const
Visitor interface for model dispatch.
Definition Model.hpp:34
Abstract base class for predictive models (trees and forests).
Definition Model.hpp:25
TrainingSpec::Ptr training_spec
Training specification used to build this model.
Definition Model.hpp:45
Tag type for requesting vote-proportion predictions.
Definition Model.hpp:19
Training configuration for projection pursuit trees and forests.
Definition TrainingSpec.hpp:40
std::shared_ptr< TrainingSpec > Ptr
Definition TrainingSpec.hpp:41