Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

prapi::Classifier< T, I, C > Class Template Reference

#include <Classifier.h>

Inheritance diagram for prapi::Classifier< T, I, C >:

EventSource< ClassificationEvent< T, I, C > > Object prapi::kNNClassifier< T, I, C > prapi::MahalanobisClassifier< T, I, C > prapi::MinimumDistanceClassifier< T, I, C > prapi::NNClassifier< T, I, C > List of all members.

Detailed Description

template<class T, class I = std::string, class C = int>
class prapi::Classifier< T, I, C >

Classifier is the common base class for all types of classifiers.

Classifier modifies the testing samples by setting their classification field to a new value.

Classifier stores a pointer to the training samples and proximity measure for memory saving purposes. Take care that the training samples won't be deleted before the Classifier has done its due.

If you want to keep track of the state of the classification, you might want to add some EventListeners to a classifier. After each classified sample, all registered event listeners are notified.

The purpose of a classifier is just to set the classification for a set of samples. When you want to get more information of the classification result, use a confusion matrix for the classified sample set.

See also:
ConfusionMatrix


Public Methods

 Classifier (util::List< Sample< T, I, C > > *trainingSamples=NULL, ProximityMeasure< T > *measure=NULL, int classCount=-1)
 Create a new classifier.

 Classifier (util::List< Sample< T, I, C > > &trainingSamples, ProximityMeasure< T > *measure, int classCount)
 Create a new classifier.

 Classifier (util::List< Sample< T, I, C > > &trainingSamples, ProximityMeasure< T > &measure, int classCount)
 Create a new classifier.

virtual ~Classifier ()
 The Destructor of Classifier.

virtual void holdOut (util::List< Sample< T, I, C > > &lst) throw (ClassificationException&)
 Perform a holdout test using the given samples as testing data.

virtual void leaveOneOut (void) throw (ClassificationException&)
 Perform a leave-one-out test on the training data.

virtual C getClassification (Sample< T, I, C > &sample)=0 throw (ClassificationException&)
 Get the classification for a single sample.

virtual util::List< int > getRanks (Sample< T, I, C > &sample) throw (ClassificationException&)
 Sort all classes according to their proximity to a given test sample.

virtual void setTrainingSamples (util::List< Sample< T, I, C > > *lst)
 Change the training samples held by this classifier.

util::List< Sample< T, I,
C > > * 
getTrainingSamples (void)
 Get the training samples held by this classifier.

const util::List< Sample<
T, I, C > > * 
getTrainingSamples (void) const
 Get the training samples held by this classifier.

util::List< Sample< T, I,
C > > *& 
trainingSamples (void)
 Get the training samples held by this classifier.

void setProximityMeasure (ProximityMeasure< T > *measure)
 Set the proximity (distance) measure used in classification.

void setProximityMeasure (ProximityMeasure< T > &measure)
 Set the proximity (distance) measure used in classification.

ProximityMeasure< T > * getProximityMeasure (void) const
 Get a pointer to the proximity measure.

void setClassCount (int count)
 Set the class count for this classifier.

int getClassCount (void) const
 Get the class count.

int & classCount (void)
 Get the class count.

void setAutodeleteMeasure (bool del)
 Enable or disable the automatic deletion of the proximity measure.

bool getAutodeleteMeasure (void) const
 See whether the classifier is going to automatically delete its proximity measure.

bool & autodeleteMeasure (void)
 Directly access the autorelease mode flag.


Static Public Methods

util::List< Sample< T, I,
C > > 
selectRandomly (const util::List< Sample< T, I, C > > &samples, int n) throw (InvalidArgumentException&)
 Randomly select n samples from samples.

void divide (const util::List< Sample< T, I, C > > &samples, util::List< Sample< T, I, C > > &correct, util::List< Sample< T, I, C > > &wrong)
 Divide the given sample list into two disjoint sets, one containing the correctly classified samples and the other containing the rest.

util::List< util::List< Sample<
T, I, C > > > 
divide (const util::List< Sample< T, I, C > > &samples, util::List< int > &classes) throw (ClassificationException&)
 Divide the given sample list into disjoint sets.

util::List< util::List< Sample<
T, I, C > > > 
divideByTrueClass (const util::List< Sample< T, I, C > > &samples, util::List< int > &classes) throw (ClassificationException&)
 DivideByTrueClass divides a sample set according to the true class of a sample (divide(samples,classes) divides by the classification).


Protected Attributes

util::List< Sample< T, I,
C > > * 
_lstpTrainingSamples
 A pointer to the list of training samples.

ProximityMeasure< T > * _proximityMeasure
 A pointer to the code used to measure proximities between samples.

int _iClassCount
 The number of classes.


Constructor & Destructor Documentation

template<class T, class I, class C>
prapi::Classifier< T, I, C >::Classifier util::List< Sample< T, I, C > > *    trainingSamples = NULL,
ProximityMeasure< T > *    measure = NULL,
int    classCount = -1
 

Create a new classifier.

The memory pointed by measure is automatically released upon the deletion of the classifier. Training samples are not deleted automatically. That is, you can create a Classifier like the following:

 MyClassifier classifier(&trainingSamples, new MyProximityMeasure, classes);
 
One does not need to store a pointer to "new MyProximityMeasure" as the memory is released automatically.
Parameters:
trainingSamples  a pointer to a list of samples to be used in training
measure  a proximity measure for classification (autodelete)
classCount  total number of classes in the data

template<class T, class I, class C>
prapi::Classifier< T, I, C >::Classifier util::List< Sample< T, I, C > > &    trainingSamples,
ProximityMeasure< T > *    measure,
int    classCount
 

Create a new classifier.

The memory pointed by measure is automatically released upon the deletion of the classifier. Training samples are not deleted automatically.

Parameters:
trainingSamples  a reference to a list of samples to be used in training
measure  a proximity measure for classification (autodelete)
classCount  total number of classes in the data

template<class T, class I, class C>
prapi::Classifier< T, I, C >::Classifier util::List< Sample< T, I, C > > &    trainingSamples,
ProximityMeasure< T > &    measure,
int    classCount
 

Create a new classifier.

Parameters:
trainingSamples  a reference to a list of samples to be used in training
measure  a proximity measure for classification
classCount  total number of classes in the data

template<class T, class I = std::string, class C = int>
virtual prapi::Classifier< T, I, C >::~Classifier   [inline, virtual]
 

The Destructor of Classifier.

If Autodelete mesure is on the measure will be deleted.


Member Function Documentation

template<class T, class I, class C>
util::List< util::List< Sample< T, I, C > > > prapi::Classifier< T, I, C >::divide const util::List< Sample< T, I, C > > &    samples,
util::List< int > &    classes
throw (ClassificationException&) [static]
 

Divide the given sample list into disjoint sets.

The number of disjoint sets depends on the number of classes given from the IntegerList classes. (Example: if classes has number 3 at the index 2, then all samples that have been classified to class 2 are added to the list index 3). Return List contain classes from 0 to max integer given in classes.

Parameters:
samples  a list of samples to be divided
classes  a list which tell where to put specified sample
Returns:
the List of different classes in List<Sample<T,I,C> > format

template<class T, class I, class C>
void prapi::Classifier< T, I, C >::divide const util::List< Sample< T, I, C > > &    samples,
util::List< Sample< T, I, C > > &    correct,
util::List< Sample< T, I, C > > &    wrong
[static]
 

Divide the given sample list into two disjoint sets, one containing the correctly classified samples and the other containing the rest.

Parameters:
samples  a list of samples to be divided
corret  a list for storing correctly classified samples
corret  a list for storing incorrectly classified samples

template<class T, class I, class C>
util::List< util::List< Sample< T, I, C > > > prapi::Classifier< T, I, C >::divideByTrueClass const util::List< Sample< T, I, C > > &    samples,
util::List< int > &    classes
throw (ClassificationException&) [static]
 

DivideByTrueClass divides a sample set according to the true class of a sample (divide(samples,classes) divides by the classification).

Parameters:
samples  a list of samples to be divided
classes  a list of mappings for placing samples
Returns:
the List of different classes in List<Sample<T,I,C> > format

template<class T, class I = std::string, class C = int>
virtual C prapi::Classifier< T, I, C >::getClassification Sample< T, I, C > &    sample throw (ClassificationException&) [pure virtual]
 

Get the classification for a single sample.

This method is used by holdOut and leaveOneOut to classify each sample. Subclasses must override this method.

Parameters:
sample  the sample to be classified
Returns:
the classification. Simple classfiers (like NN or kNN) use integers. More sophisticated ones may use any classification type.
See also:
Sample for more information.

Implemented in prapi::NNClassifier< T, I, C >, prapi::kNNClassifier< T, I, C >, prapi::MinimumDistanceClassifier< T, I, C >, prapi::MahalanobisClassifier< T, I, C >, prapi::MultiClassifier< T, I >, and prapi::VQClassifier< I, C >.

template<class T, class I, class C>
util::List< int > prapi::Classifier< T, I, C >::getRanks Sample< T, I, C > &    sample throw (ClassificationException&) [virtual]
 

Sort all classes according to their proximity to a given test sample.

The default implementation loops through all training samples and finds the closest match from each class using the internal proximity measure. It then ranks the classes according to the obtained proximities. The larger the rank, the worse the match.

Parameters:
sample  the sample for which class ranks are to be obtained
Returns:
the rank number for each class. The length of the returned list is equal to the number classes, and each slot in the list represents the rank of the corresponding class. Note that some classifiers may be unable to produce rankings. In this case, this list contains a zero in the slot of the winning class and ones elsewhere.

template<class T, class I, class C>
void prapi::Classifier< T, I, C >::holdOut util::List< Sample< T, I, C > > &    lst throw (ClassificationException&) [virtual]
 

Perform a holdout test using the given samples as testing data.

Parameters:
lst  testing samples

template<class T, class I, class C>
util::List< Sample< T, I, C > > prapi::Classifier< T, I, C >::selectRandomly const util::List< Sample< T, I, C > > &    samples,
int    n
throw (InvalidArgumentException&) [static]
 

Randomly select n samples from samples.

Parameters:
samples  the samples from which samples are to be selected
n  the number of samples to select
Returns:
the selected samples

template<class T, class I = std::string, class C = int>
void prapi::Classifier< T, I, C >::setAutodeleteMeasure bool    del [inline]
 

Enable or disable the automatic deletion of the proximity measure.

You will probably not need this method, but if you do, take enormous care that memory is not released twice.

Parameters:
del  if true, memory allocated by the proximity measure is automatically released on deletion of the Classifier and in setProximityMeasure().

template<class T, class I = std::string, class C = int>
void prapi::Classifier< T, I, C >::setClassCount int    count [inline]
 

Set the class count for this classifier.

The number does not actually matter for some classifiers, but you might want to keep it correct in any case.

template<class T, class I, class C>
void prapi::Classifier< T, I, C >::setProximityMeasure ProximityMeasure< T > &    measure
 

Set the proximity (distance) measure used in classification.

If Classifier is initialized using a pointer to a proximity measure (autodelete mode), then the memory allocated by the old measure is automatically released. Autodelete mode will be turned off upon the exit of this method.

Parameters:
measure  the new proximity measure

template<class T, class I, class C>
void prapi::Classifier< T, I, C >::setProximityMeasure ProximityMeasure< T > *    measure
 

Set the proximity (distance) measure used in classification.

If Classifier is initialized using a pointer to a proximity measure (autodelete mode), then the memory allocated by the old measure is automatically released. Autodelete mode will be turned on upon the exit of this method.

Parameters:
measure  the new proximity measure

template<class T, class I = std::string, class C = int>
virtual void prapi::Classifier< T, I, C >::setTrainingSamples util::List< Sample< T, I, C > > *    lst [inline, virtual]
 

Change the training samples held by this classifier.

Parameters:
lst  the new samples

Reimplemented in prapi::MinimumDistanceClassifier< T, I, C >, and prapi::MahalanobisClassifier< T, I, C >.


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.