[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra::rf3 Namespace Reference

Random forest version 3. More...

Classes

class  DepthStop
 Random forest 'maximum depth' stop criterion. More...
 
class  EntropyScore
 Functor that computes the entropy score. More...
 
class  GiniScore
 Functor that computes the gini score. More...
 
class  KolmogorovSmirnovScore
 Functor that computes the Kolmogorov-Smirnov score. More...
 
class  NodeComplexityStop
 Random forest 'node complexity' stop criterion. More...
 
class  NumInstancesStop
 Random forest 'number of datapoints' stop criterion. More...
 
class  OOBError
 Compute the out of bag error. More...
 
class  PurityStop
 Random forest 'node purity' stop criterion. More...
 
class  RandomForest
 Random forest version 3. More...
 
class  RandomForestOptions
 Options class for RandomForest version 3. More...
 
class  RFStopVisiting
 The default visitor node (= "do nothing"). More...
 
class  RFVisitorBase
 Base class from which all random forest visitors derive. More...
 
class  VariableImportance
 Compute the variable importance. More...
 
struct  VisitorCopy
 

Functions

template<...>
void random_forest (...)
 Train a RandomForest classifier.
 

Detailed Description

Random forest version 3.

This namespace contains VIGRA's 3rd version of the random forest classification/regression algorithm. This version is much easier to customize than previous versions because it consequently separates algorithms from the forest representation, following the design of the LEMON graph library.

Function Documentation

◆ random_forest()

template<...>
void random_forest ( ...)

Train a RandomForest classifier.

This factory function constructs a RandomForest classifier and trains it for the given features and labels. They must be given as a matrix with shape num_instances x num_features and an array with length num_instances respectively. Most training options (such as number of trees in the forest, termination and split criteria, and number of threads for parallel training) are specified via an option object of type RandomForestOptions. Optional visitors are typically used to compute the out-of-bag error of the classifier (use OOBError) and estimate variable importance on the basis of the Gini gain (use VariableImportance). You can also provide a specific random number generator instance, which is especially useful when you want to enforce deterministic algorithm behavior during debugging.

Declaration:

namespace vigra { namespace rf3 {
template <typename FEATURES,
typename LABELS,
typename VISITOR = vigra::rf3::RFStopVisiting,
typename RANDENGINE = vigra::MersenneTwister>
FEATURES const & features,
LABELS const & labels,
VISITOR visitor = vigra::rf3::RFStopVisiting(),
RANDENGINE & randengine = vigra::MersenneTwister::global()
);
}}
static RandomNumberGenerator & global()
Definition random.hxx:573
The default visitor node (= "do nothing").
Definition random_forest_visitors.hxx:510
Options class for RandomForest version 3.
Definition random_forest_common.hxx:583
Random forest version 3.
Definition random_forest.hxx:69
Random forest version 3.
Definition random_forest_3.hxx:66
void random_forest(...)
Train a RandomForest classifier.
RandomNumberGenerator< detail::RandomState< detail::MT19937 > > MersenneTwister
Definition random.hxx:634

Usage:

#include <vigra/random_forest_3.hxx>
Namespace: vigra::rf3

using namespace vigra;
int num_instances = ...;
int num_features = ...;
MultiArray<2, double> train_features(Shape2(num_instances, num_features));
MultiArray<1, int> train_labels(Shape1(num_instances));
... // fill training data matrices
rf3::OOBError oob; // visitor to compute the out-of-bag error
auto rf = random_forest(train_features, train_labels,
rf3::RandomForestOptions().tree_count(100)
.features_per_node(rf3::RF_SQRT)
.n_threads(4)
rf3::create_visitor(oob));
std::cout << "Random forest training finished with out-of-bag error " << oob.oob_err_ << "\n";
int num_test_instances = ...;
MultiArray<2, double> test_features(Shape2(num_test_instances, num_features));
MultiArray<1, int> test_labels(Shape1(num_test_instances));
... // fill feature matrix for test data
rf.predict(test_features, test_labels);
for(int i=0; i<num_test_instances; ++i)
std::cerr << "Prediction for test instance " << i << ": " << test_labels(i) << "\n";
Main MultiArray class containing the memory management.
Definition multi_array.hxx:2479
Compute the out of bag error.
Definition random_forest_visitors.hxx:173
double oob_err_
Definition random_forest_visitors.hxx:246

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.12.1 (Thu Feb 27 2025)