Builds clsfy_random_forest classifiers. More...
#include <clsfy_random_forest_builder.h>
Public Member Functions | |
clsfy_random_forest_builder () | |
clsfy_random_forest_builder (unsigned ntrees, int max_depth=-1, int min_node_size=-1) | |
virtual | ~clsfy_random_forest_builder () |
virtual clsfy_classifier_base * | new_classifier () const |
Create empty model. | |
virtual double | build (clsfy_classifier_base &classifier, mbl_data_wrapper< vnl_vector< double > > &inputs, unsigned nClasses, const vcl_vector< unsigned > &outputs) const |
Build classifier from data. | |
virtual vcl_string | is_a () const |
Name of the class. | |
virtual bool | is_class (vcl_string const &s) const |
Name of the class. | |
short | version_no () const |
IO Version number. | |
virtual clsfy_builder_base * | clone () const |
Create a copy on the heap and return base class pointer. | |
virtual void | print_summary (vcl_ostream &os) const |
Print class to os. | |
virtual void | b_write (vsl_b_ostream &bfs) const |
Save class to binary file stream. | |
virtual void | b_read (vsl_b_istream &bfs) |
Load class from binary file stream. | |
int | max_depth () const |
The max tree depth (default -1 means no max set ). | |
void | set_max_depth (int max_depth) |
Set the number of nearest neighbours to look for. | |
int | min_node_size () const |
void | set_min_node_size (int min_node_size) |
Set minimum number of points associated with any node. | |
void | set_ntrees (unsigned ntrees) |
set number of trees in forest. | |
unsigned | ntrees () const |
virtual void | seed_sampler (unsigned long seed) |
void | set_calc_test_error (bool on) |
set whether the build calculates a test error over the input training set. | |
void | set_oob_indices (vcl_vector< vcl_vector< unsigned > > *poobIndices) |
Save a pointer to storage for out of bag indices. | |
virtual void | config (vcl_istream &as) |
Initialise the parameters from a text stream. | |
Static Public Member Functions | |
static vcl_auto_ptr < clsfy_builder_base > | new_builder (vcl_istream &as) |
Load description from a text stream. | |
Protected Member Functions | |
virtual unsigned | select_nbranch_params (unsigned ndims) const |
Pick the number of parameters that the tree builder branches on. | |
virtual void | select_data (vcl_vector< vnl_vector< double > > &inputs, const vcl_vector< unsigned > &outputs, vcl_vector< vnl_vector< double > > &bootstrapped_inputs, vcl_vector< unsigned > &bootstrapped_outputs) const |
Pick a random data subset (with replacement). | |
virtual unsigned long | get_tree_builder_seed () const |
Protected Attributes | |
unsigned | ntrees_ |
Number of trees. | |
int | max_depth_ |
The max depth of any child tree. | |
int | min_node_size_ |
Minimum number of points associated with any node. | |
vnl_random | random_sampler_ |
Uniform sampler on 0,1 (for bootstrapping). | |
vcl_vector< vcl_vector < unsigned > > * | poob_indices_ |
Pointer to storage of point indices for each bootstrapped tree. | |
Private Attributes | |
bool | calc_test_error_ |
Does the builder calculate the error on the training set?. |
Builds clsfy_random_forest classifiers.
Definition at line 25 of file clsfy_random_forest_builder.h.
clsfy_random_forest_builder::clsfy_random_forest_builder | ( | ) |
Definition at line 26 of file clsfy_random_forest_builder.cxx.
clsfy_random_forest_builder::clsfy_random_forest_builder | ( | unsigned | ntrees, |
int | max_depth = -1 , |
||
int | min_node_size = -1 |
||
) |
Definition at line 36 of file clsfy_random_forest_builder.cxx.
clsfy_random_forest_builder::~clsfy_random_forest_builder | ( | ) | [virtual] |
Definition at line 48 of file clsfy_random_forest_builder.cxx.
void clsfy_random_forest_builder::b_read | ( | vsl_b_istream & | bfs | ) | [virtual] |
Load class from binary file stream.
Implements clsfy_builder_base.
Definition at line 100 of file clsfy_random_forest_builder.cxx.
void clsfy_random_forest_builder::b_write | ( | vsl_b_ostream & | bfs | ) | const [virtual] |
Save class to binary file stream.
Implements clsfy_builder_base.
Definition at line 88 of file clsfy_random_forest_builder.cxx.
double clsfy_random_forest_builder::build | ( | clsfy_classifier_base & | classifier, |
mbl_data_wrapper< vnl_vector< double > > & | inputs, | ||
unsigned | nClasses, | ||
const vcl_vector< unsigned > & | outputs | ||
) | const [virtual] |
Build classifier from data.
Build model from data.
return the mean error over the training set.
return the mean error over the training set. For many classifiers, you may use nClasses==1 to indicate a binary classifier
Implements clsfy_builder_base.
Definition at line 127 of file clsfy_random_forest_builder.cxx.
clsfy_builder_base * clsfy_random_forest_builder::clone | ( | ) | const [virtual] |
Create a copy on the heap and return base class pointer.
Implements clsfy_builder_base.
Definition at line 74 of file clsfy_random_forest_builder.cxx.
void clsfy_builder_base::config | ( | vcl_istream & | as | ) | [virtual, inherited] |
Initialise the parameters from a text stream.
Default case accepts no parameters.
Reimplemented in clsfy_rbf_svm_smo_1_builder, clsfy_parzen_builder, clsfy_knn_builder, clsfy_null_builder, and clsfy_binary_1d_wrapper_builder.
Definition at line 26 of file clsfy_builder_base.cxx.
unsigned long clsfy_random_forest_builder::get_tree_builder_seed | ( | ) | const [protected, virtual] |
Definition at line 256 of file clsfy_random_forest_builder.cxx.
vcl_string clsfy_random_forest_builder::is_a | ( | ) | const [virtual] |
Name of the class.
Reimplemented from clsfy_builder_base.
Definition at line 60 of file clsfy_random_forest_builder.cxx.
bool clsfy_random_forest_builder::is_class | ( | vcl_string const & | s | ) | const [virtual] |
Name of the class.
Reimplemented from clsfy_builder_base.
Definition at line 67 of file clsfy_random_forest_builder.cxx.
int clsfy_random_forest_builder::max_depth | ( | ) | const [inline] |
The max tree depth (default -1 means no max set ).
Definition at line 68 of file clsfy_random_forest_builder.h.
int clsfy_random_forest_builder::min_node_size | ( | ) | const [inline] |
Definition at line 76 of file clsfy_random_forest_builder.h.
vcl_auto_ptr< clsfy_builder_base > clsfy_builder_base::new_builder | ( | vcl_istream & | as | ) | [static, inherited] |
Load description from a text stream.
The stream should contain the name of the feature extractor class that will be used, followed by a brace-enclosed list of parameters for the builder. This function will construct the appropriate clsfy_builder_base derivative and return that.
if | the parse fails. |
Definition at line 42 of file clsfy_builder_base.cxx.
clsfy_classifier_base * clsfy_random_forest_builder::new_classifier | ( | ) | const [virtual] |
Create empty model.
Create empty classifier.
Caller is responsible for deletion
Implements clsfy_builder_base.
Definition at line 209 of file clsfy_random_forest_builder.cxx.
unsigned clsfy_random_forest_builder::ntrees | ( | ) | const [inline] |
Definition at line 90 of file clsfy_random_forest_builder.h.
void clsfy_random_forest_builder::print_summary | ( | vcl_ostream & | os | ) | const [virtual] |
Print class to os.
Implements clsfy_builder_base.
Definition at line 81 of file clsfy_random_forest_builder.cxx.
void clsfy_random_forest_builder::seed_sampler | ( | unsigned long | seed | ) | [virtual] |
Definition at line 251 of file clsfy_random_forest_builder.cxx.
void clsfy_random_forest_builder::select_data | ( | vcl_vector< vnl_vector< double > > & | inputs, |
const vcl_vector< unsigned > & | outputs, | ||
vcl_vector< vnl_vector< double > > & | bootstrapped_inputs, | ||
vcl_vector< unsigned > & | bootstrapped_outputs | ||
) | const [protected, virtual] |
Pick a random data subset (with replacement).
Definition at line 215 of file clsfy_random_forest_builder.cxx.
unsigned clsfy_random_forest_builder::select_nbranch_params | ( | unsigned | ndims | ) | const [protected, virtual] |
Pick the number of parameters that the tree builder branches on.
Default uses sqrt of ndims
Definition at line 240 of file clsfy_random_forest_builder.cxx.
void clsfy_random_forest_builder::set_calc_test_error | ( | bool | on | ) | [inline] |
set whether the build calculates a test error over the input training set.
Default is on, but this can be turned off e.g. for a parallel build of many partial random forests of which can be later merged
Definition at line 98 of file clsfy_random_forest_builder.h.
void clsfy_random_forest_builder::set_max_depth | ( | int | max_depth | ) | [inline] |
Set the number of nearest neighbours to look for.
If not see default is high value to force continuation till all final leaf nodes are pure (i.e. single class) If set negative the value is ignored
Definition at line 74 of file clsfy_random_forest_builder.h.
void clsfy_random_forest_builder::set_min_node_size | ( | int | min_node_size | ) | [inline] |
Set minimum number of points associated with any node.
If negative this is ignored, otherwise if a split would produce a child node less than this, then the split does not occur and the branch is terminated
Definition at line 82 of file clsfy_random_forest_builder.h.
void clsfy_random_forest_builder::set_ntrees | ( | unsigned | ntrees | ) | [inline] |
set number of trees in forest.
Note this must be set before calling build Default is 100
Definition at line 88 of file clsfy_random_forest_builder.h.
void clsfy_random_forest_builder::set_oob_indices | ( | vcl_vector< vcl_vector< unsigned > > * | poobIndices | ) | [inline] |
Save a pointer to storage for out of bag indices.
Definition at line 101 of file clsfy_random_forest_builder.h.
short clsfy_random_forest_builder::version_no | ( | ) | const |
IO Version number.
Definition at line 53 of file clsfy_random_forest_builder.cxx.
bool clsfy_random_forest_builder::calc_test_error_ [private] |
Does the builder calculate the error on the training set?.
Definition at line 141 of file clsfy_random_forest_builder.h.
int clsfy_random_forest_builder::max_depth_ [protected] |
The max depth of any child tree.
If negative no max is applied, and all final leaf nodes are pure (i.e. single class)
Definition at line 122 of file clsfy_random_forest_builder.h.
int clsfy_random_forest_builder::min_node_size_ [protected] |
Minimum number of points associated with any node.
If negative this is ignored, otherwise if a split would produce a child node less than this, then the split does not occur and the branch is terminated
Definition at line 129 of file clsfy_random_forest_builder.h.
unsigned clsfy_random_forest_builder::ntrees_ [protected] |
Number of trees.
Definition at line 118 of file clsfy_random_forest_builder.h.
vcl_vector<vcl_vector<unsigned > >* clsfy_random_forest_builder::poob_indices_ [protected] |
Pointer to storage of point indices for each bootstrapped tree.
Can be used for out of bag estimates Saves for tree i the indices of all points used in its training Note the storage is supplied from outside this class, as this is a kind of bolt-on
Definition at line 138 of file clsfy_random_forest_builder.h.
vnl_random clsfy_random_forest_builder::random_sampler_ [mutable, protected] |
Uniform sampler on 0,1 (for bootstrapping).
Definition at line 132 of file clsfy_random_forest_builder.h.