Public Member Functions | Static Public Member Functions | Private Attributes
clsfy_knn_builder Class Reference

Builds clsfy_k_nearest_neighbour classifiers. More...

#include <clsfy_knn_builder.h>

Inheritance diagram for clsfy_knn_builder:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 clsfy_knn_builder ()
virtual clsfy_classifier_basenew_classifier () const
 Create empty model.
virtual double build (clsfy_classifier_base &model, 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.
unsigned k () const
 The number of nearest neighbours to look for.
void set_k (unsigned)
 Set the number of nearest neighbours to look for.
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.

Private Attributes

unsigned k_
 The number of nearest neighbours to look for.

Detailed Description

Builds clsfy_k_nearest_neighbour classifiers.

This class doesn't do any calculation, it is easy to create a knn classifier directly - but it allows for consistent swappable classifiers.

Definition at line 26 of file clsfy_knn_builder.h.


Constructor & Destructor Documentation

clsfy_knn_builder::clsfy_knn_builder ( )

Definition at line 26 of file clsfy_knn_builder.cxx.


Member Function Documentation

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

Load class from binary file stream.

Implements clsfy_builder_base.

Definition at line 78 of file clsfy_knn_builder.cxx.

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

Save class to binary file stream.

Implements clsfy_builder_base.

Definition at line 69 of file clsfy_knn_builder.cxx.

double clsfy_knn_builder::build ( clsfy_classifier_base model,
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 102 of file clsfy_knn_builder.cxx.

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

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

Implements clsfy_builder_base.

Definition at line 55 of file clsfy_knn_builder.cxx.

void clsfy_knn_builder::config ( vcl_istream &  as) [virtual]

Initialise the parameters from a text stream.

The next non-ws character in the stream should be a '{'

   {
     k: 3  (default 1)
   }
   
Exceptions:
mbl_exception_parse_errorif the parse fails.

Reimplemented from clsfy_builder_base.

Definition at line 159 of file clsfy_knn_builder.cxx.

vcl_string clsfy_knn_builder::is_a ( ) const [virtual]

Name of the class.

Reimplemented from clsfy_builder_base.

Definition at line 41 of file clsfy_knn_builder.cxx.

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

Name of the class.

Reimplemented from clsfy_builder_base.

Definition at line 48 of file clsfy_knn_builder.cxx.

unsigned clsfy_knn_builder::k ( ) const

The number of nearest neighbours to look for.

Definition at line 130 of file clsfy_knn_builder.cxx.

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_knn_builder::new_classifier ( ) const [virtual]

Create empty model.

Create empty classifier.

Caller is responsible for deletion

Implements clsfy_builder_base.

Definition at line 145 of file clsfy_knn_builder.cxx.

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

Print class to os.

Implements clsfy_builder_base.

Definition at line 62 of file clsfy_knn_builder.cxx.

void clsfy_knn_builder::set_k ( unsigned  k)

Set the number of nearest neighbours to look for.

Definition at line 137 of file clsfy_knn_builder.cxx.

short clsfy_knn_builder::version_no ( ) const

IO Version number.

Definition at line 34 of file clsfy_knn_builder.cxx.


Member Data Documentation

unsigned clsfy_knn_builder::k_ [private]

The number of nearest neighbours to look for.

Definition at line 29 of file clsfy_knn_builder.h.


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