Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
clsfy_binary_tree_builder Class Reference

Builds clsfy_binary_tree classifiers. More...

#include <clsfy_binary_tree_builder.h>

Inheritance diagram for clsfy_binary_tree_builder:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 clsfy_binary_tree_builder ()
virtual clsfy_classifier_basenew_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_baseclone () 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_nbranch_params (int nbranch_params)
 Set this for random forest behaviour.
void set_calc_test_error (bool on)
 set whether the build calculates a test error over the input training set.
void seed_sampler (unsigned long seed)
 Seed the sample used to select branching parameter subsets.
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 void randomise_parameters (unsigned ndimsUsed, vcl_vector< unsigned > &param_indices) const
 Randomly select the ndimsUsed dimensions for current branch.

Protected Attributes

vnl_random random_sampler_

Private Member Functions

void build_children (const vcl_vector< vnl_vector< double > > &vin, const vcl_vector< unsigned > &outputs, clsfy_binary_tree_bnode *parent, bool to_left) const
void copy_children (clsfy_binary_tree_bnode *pBuilderNode, clsfy_binary_tree_node *pNode) const
void set_node_prob (clsfy_binary_tree_node *pNode, clsfy_binary_tree_bnode *pBuilderNode) const
void build_a_node (const vcl_vector< vnl_vector< double > > &vin, const vcl_vector< unsigned > &outputs, const vcl_set< unsigned > &subIndices, clsfy_binary_tree_bnode *pNode) const
bool isNodePure (const vcl_set< unsigned > &subIndices, const vcl_vector< unsigned > &outputs) const
void add_terminator (const vcl_vector< vnl_vector< double > > &vin, const vcl_vector< unsigned > &outputs, clsfy_binary_tree_bnode *parent, bool to_left, bool pure) const
 Add dummy node to represent a pure node.

Private Attributes

int max_depth_
 The max depth of any leaf node in the tree.
int min_node_size_
 Minimum number of points associated with any node.
int nbranch_params_
 Set this for random forest behaviour.
vcl_vector< unsigned > base_indices_
 Work space for randomising params (NB not thread safe).
bool calc_test_error_

Detailed Description

Builds clsfy_binary_tree classifiers.

Keep finding the variable split that gives the least min_error for a binary threshold. Divide up the dataset by that and keep recursively building binary threshold classifiers in a tree structure till either Max depth level reached, or a node is pure, or node's data <min_nide_size

Definition at line 51 of file clsfy_binary_tree_builder.h.


Constructor & Destructor Documentation

clsfy_binary_tree_builder::clsfy_binary_tree_builder ( )

Definition at line 26 of file clsfy_binary_tree_builder.cxx.


Member Function Documentation

void clsfy_binary_tree_builder::add_terminator ( const vcl_vector< vnl_vector< double > > &  vin,
const vcl_vector< unsigned > &  outputs,
clsfy_binary_tree_bnode parent,
bool  left,
bool  pure 
) const [private]

Add dummy node to represent a pure node.

The threshold is set either very low or very high

Definition at line 454 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::b_read ( vsl_b_istream bfs) [virtual]

Load class from binary file stream.

Implements clsfy_builder_base.

Definition at line 83 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::b_write ( vsl_b_ostream bfs) const [virtual]

Save class to binary file stream.

Implements clsfy_builder_base.

Definition at line 71 of file clsfy_binary_tree_builder.cxx.

double clsfy_binary_tree_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 111 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::build_a_node ( const vcl_vector< vnl_vector< double > > &  vin,
const vcl_vector< unsigned > &  outputs,
const vcl_set< unsigned > &  subIndices,
clsfy_binary_tree_bnode pNode 
) const [private]

Definition at line 321 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::build_children ( const vcl_vector< vnl_vector< double > > &  vin,
const vcl_vector< unsigned > &  outputs,
clsfy_binary_tree_bnode parent,
bool  to_left 
) const [private]

Definition at line 198 of file clsfy_binary_tree_builder.cxx.

clsfy_builder_base * clsfy_binary_tree_builder::clone ( ) const [virtual]

Create a copy on the heap and return base class pointer.

Implements clsfy_builder_base.

Definition at line 57 of file clsfy_binary_tree_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.

void clsfy_binary_tree_builder::copy_children ( clsfy_binary_tree_bnode pBuilderNode,
clsfy_binary_tree_node pNode 
) const [private]

Definition at line 301 of file clsfy_binary_tree_builder.cxx.

vcl_string clsfy_binary_tree_builder::is_a ( ) const [virtual]

Name of the class.

Reimplemented from clsfy_builder_base.

Definition at line 43 of file clsfy_binary_tree_builder.cxx.

bool clsfy_binary_tree_builder::is_class ( vcl_string const &  s) const [virtual]

Name of the class.

Reimplemented from clsfy_builder_base.

Definition at line 50 of file clsfy_binary_tree_builder.cxx.

bool clsfy_binary_tree_builder::isNodePure ( const vcl_set< unsigned > &  subIndices,
const vcl_vector< unsigned > &  outputs 
) const [private]

Definition at line 435 of file clsfy_binary_tree_builder.cxx.

int clsfy_binary_tree_builder::max_depth ( ) const [inline]

The max tree depth (default -1 means no max set ).

Definition at line 109 of file clsfy_binary_tree_builder.h.

int clsfy_binary_tree_builder::min_node_size ( ) const [inline]

Definition at line 117 of file clsfy_binary_tree_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.

Exceptions:
ifthe parse fails.

Definition at line 42 of file clsfy_builder_base.cxx.

clsfy_classifier_base * clsfy_binary_tree_builder::new_classifier ( ) const [virtual]

Create empty model.

Create empty classifier.

Caller is responsible for deletion

Implements clsfy_builder_base.

Definition at line 512 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::print_summary ( vcl_ostream &  os) const [virtual]

Print class to os.

Implements clsfy_builder_base.

Definition at line 64 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::randomise_parameters ( unsigned  ndimsUsed,
vcl_vector< unsigned > &  param_indices 
) const [protected, virtual]

Randomly select the ndimsUsed dimensions for current branch.

Return indices of selected parameters Best of these is then chosen as the branch

Definition at line 517 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_builder::seed_sampler ( unsigned long  seed)

Seed the sample used to select branching parameter subsets.

Definition at line 529 of file clsfy_binary_tree_builder.cxx.

void clsfy_binary_tree_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 random forest of many child trees

Definition at line 133 of file clsfy_binary_tree_builder.h.

void clsfy_binary_tree_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 115 of file clsfy_binary_tree_builder.h.

void clsfy_binary_tree_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 123 of file clsfy_binary_tree_builder.h.

void clsfy_binary_tree_builder::set_nbranch_params ( int  nbranch_params) [inline]

Set this for random forest behaviour.

At each split the selection is only from a random subset of this size If negative then it is ignored

Definition at line 128 of file clsfy_binary_tree_builder.h.

void clsfy_binary_tree_builder::set_node_prob ( clsfy_binary_tree_node pNode,
clsfy_binary_tree_bnode pBuilderNode 
) const [private]

Definition at line 534 of file clsfy_binary_tree_builder.cxx.

short clsfy_binary_tree_builder::version_no ( ) const

IO Version number.

Definition at line 36 of file clsfy_binary_tree_builder.cxx.


Member Data Documentation

vcl_vector<unsigned > clsfy_binary_tree_builder::base_indices_ [mutable, private]

Work space for randomising params (NB not thread safe).

Definition at line 70 of file clsfy_binary_tree_builder.h.

Definition at line 173 of file clsfy_binary_tree_builder.h.

The max depth of any leaf node in the tree.

If negative no max is applied, and all final leaf nodes are pure (i.e. single class)

Definition at line 56 of file clsfy_binary_tree_builder.h.

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 62 of file clsfy_binary_tree_builder.h.

Set this for random forest behaviour.

At each split the selection is only from a random subset of this size If negative (default) it is ignored and all are used

Definition at line 67 of file clsfy_binary_tree_builder.h.

Definition at line 144 of file clsfy_binary_tree_builder.h.


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