#include <Classifier.h>
Collaboration diagram for Classifier:
Public Member Functions | |
Classifier (string &modelName, DimList *dl, int nv, NameList &cn) | |
Creates a Classifier object. | |
~Classifier () | |
Destructor - just invokes deleteClassifiers(). | |
void | setNumVoters (int numVoters) |
Sets the number of voters, i.e. | |
void | setNumTrainEpochs (int nte) |
Sets the number of training epochs, that is, the number of times the training set will be presented. | |
void | setDimList (DimList *dl) |
Sets the DimList, that is, the features to use for training/testing. | |
void | setClassCap (int cc) |
Sets the class-cap: this value imposes an upper limit on the number of samples of a given class that will be used in training. | |
void | setLabelChoice (labelChoiceType lc) |
Setting the labelChoiceType defines what to do during training when multiple labels are available, and class capping is turned on. | |
void | registerParams () |
Registers model parameters with all model instances; this has to be done before a new parameter setting takes effect. | |
void | save (string &fNameTemplate) |
Saves each of the classifier model instances to a file. | |
void | load (string &fNameTemplate, string &specialRequest) |
Performs the inverse operation from Classifier::save(), loading the persistent state for the classifier model instances from a set of files. | |
void | train (ViewSet *vs) |
Trains the classifier using the samples in the ViewSet object. | |
void | test (ViewSet *vs) |
Tests the classifier based on the samples in the ViewSet, that is, generate a prediction as to the class label of each sample. | |
void | classify (View *v, vector< vector< float > > &) |
Similar to test(), but doesn't care about evaluating the performance of the classifier with respect to the ground truth labels. | |
void | setCvMode (bool cvMode) |
Accessor method. | |
bool | getCvMode () |
Accessor method. | |
void | CvTrain (ViewSet *vs) |
Performs cross-validated training: creates the required number of classifier model instances, sets CvMode to true, and then invokes train() to do the work. | |
void | CvTest (ViewSet *vs) |
Performs cross-validated testing: assumes CvMode is already set to true, and invokes test() to do the work. | |
void | CvSave (string &fNameTemplate) |
Saves the classifier model instances generated by a cross-validating training session. | |
void | CvLoad (string &fNameTemplate, int numTeSets) |
Does the inverse operation from that done by CvSave(), loading N x M classifier model instances from file. | |
valarray< int > & | getClassStats (int clIdx) |
Returns a reference to an array that tracks samples per class. | |
void | predSquare (int n, float *buf) |
A more general version of predPpm: it iterates over a square of size 'resolution', where the dimensions of the square represent the two feature dimensions with which the classifier was trained. | |
void | thematicPpm (ofstream &ost, Image &img, ofstream &confOst) |
Generates a thematic map, that is, one where a pixel's color indicates the predicted class for that pixel. | |
void | reset () |
Resets the timers, 'trained' flag, cvMode flag, and the entry counters. | |
void | deleteClassifiers () |
Frees the memory dedicated to the classifier model instances and the class histogram counters. | |
void | newClassifiers () |
Reallocates memory for the classifier model instances and the class histogram counters, then creates new classifiers. | |
void | setOutputVectorStream (ofstream &ost) |
Set up a file destination for storing distributed prediction vectors, one per sample. | |
void | setDataLabelsStream (ofstream &ost) |
Set up a file destination for storing sample labels. | |
void | setLabelVectorStream (ofstream &ost) |
Set up a file destination for storing sample label vectors. | |
void | setOutputClassStream (ofstream &ost) |
Set up a file destination for storing output predictions. | |
void | setCmatPgmStream (ofstream &ost) |
Set up a file destination for storing graphical confusion matrices at the conclusion of a test. | |
void | setPredPpmStream (ofstream &ost) |
Set up a file destination for storing graphical decision surfaces, as generated by the predPpm() method. | |
void | clearOutputStreams () |
Clear all output streams; in other words, turn off file-based outputs. | |
void | requestModelOutput (string &requestName, string &fNameTemplate) |
Provides a mechanism for requesting file-based outputs from classifier model instances (see ClassifierModel::requestOutput()). | |
void | clearModelOutputStreams () |
Invokes ClassifierModel::closeStreams() for each classifier model instance. | |
NameList & | getClassNames () |
Accessor method. | |
PropertyList * | getModelParams () |
Accessor method. | |
DimList * | getDimList () |
Accessor method. | |
void | boostVerbosity (int verbosityLevel, int debuggedEntry) |
Sometimes, an odd behavior only can be reproduced after a certain number of entries have been submitted for training, which can generate too much logged output; to simplify debugging in these situations, this function lets you boost the verbosity of logging to levels 4, 5, or 6, for a particular data entry. | |
int | getNumClassifiers () |
Accessor method. | |
int | getNumVoters () |
Accessor method. | |
int | getNumTrainEpochs () |
Accessor method. | |
ClassifierModel * | getClassifier (int i) |
Accessor method. | |
int | getLtmRequired () |
Sums the storage requirements for each of the classifier model instances. | |
float | getTrainTime () |
Accessor method. | |
float | getTestTime () |
Accessor method. | |
float | getClassifyTime () |
Accessor method. | |
float | getPercentCorrect () |
Accessor method. | |
ConfusionMatrix * | getConfusionMatrix () |
Accessor method. | |
UnitPlot * | plot2D (NameList &dimNames, NameList &classNames) |
TxtPad * | getClassStats () |
Returns a TxtPad object summarizing the class statistics in the form of a histogram specifying samples per class. | |
void | setHeartbeat (bool h) |
Accessor method. |
Classer makes a distinction between classifiers and models:
|
Creates a Classifier object.
|
|
Destructor - just invokes deleteClassifiers().
|
|
Sometimes, an odd behavior only can be reproduced after a certain number of entries have been submitted for training, which can generate too much logged output; to simplify debugging in these situations, this function lets you boost the verbosity of logging to levels 4, 5, or 6, for a particular data entry.
|
|
Similar to test(), but doesn't care about evaluating the performance of the classifier with respect to the ground truth labels. In other words, generates a set of predictions for the samples in the passed View object, storing the distributed predictions in the passed 2D vector out. As does test(), this function can also write labels and label vectors to a passed output stream.
|
|
Invokes ClassifierModel::closeStreams() for each classifier model instance.
|
|
Clear all output streams; in other words, turn off file-based outputs. This is different from and doesn't affect the logging mechanism. |
|
Does the inverse operation from that done by CvSave(), loading N x M classifier model instances from file.
|
|
Saves the classifier model instances generated by a cross-validating training session. This will generate N x M files, where N is the number of partitions in the ViewSet used for cross-validation, and M is the number of voters being used (may be 1). The file names generated will append to the template fNameTemplate the string "tXvY.wgt", where X ranges from 0 to N-1, and Y ranges from 0 to M-1. The actual saving of the classifier model instance is delegated to the model implementation.
|
|
Performs cross-validated testing: assumes CvMode is already set to true, and invokes test() to do the work.
|
|
Performs cross-validated training: creates the required number of classifier model instances, sets CvMode to true, and then invokes train() to do the work.
|
|
Frees the memory dedicated to the classifier model instances and the class histogram counters.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Returns a TxtPad object summarizing the class statistics in the form of a histogram specifying samples per class.
|
|
Returns a reference to an array that tracks samples per class. One array is maintained for each classifier model instance, so this method lets you look the array up by classifier model index.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Sums the storage requirements for each of the classifier model instances.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Accessor method.
|
|
Performs the inverse operation from Classifier::save(), loading the persistent state for the classifier model instances from a set of files. See artmap::fread() for details on the specialRequest parameter.
|
|
Reallocates memory for the classifier model instances and the class histogram counters, then creates new classifiers. Note that the new classifiers have default settings, i.e., model parameters must be applied to them anew. |
|
|
|
A more general version of predPpm: it iterates over a square of size 'resolution', where the dimensions of the square represent the two feature dimensions with which the classifier was trained. However, instead of generating a graphic, it fills a floating-point array with predictions for the class of each 'pixel' in the square.
|
|
Registers model parameters with all model instances; this has to be done before a new parameter setting takes effect. Note - to set model parameters, use getModelParams() to get a pointer to the PropertyList that stores the parameter settings, and modify the PropertyList. |
|
Provides a mechanism for requesting file-based outputs from classifier model instances (see ClassifierModel::requestOutput()). Filenames are generated in a similar manner to the way it's done in Classifier::save(), with the extension '.txt' substituted for '.wgt'. |
|
Resets the timers, 'trained' flag, cvMode flag, and the entry counters.
|
|
Saves each of the classifier model instances to a file. If there is only a single classifier model instance, the filename is fNameTemplate.wgt; if there are several instances, then file names are based on the passed template, as follows:
|
|
Sets the class-cap: this value imposes an upper limit on the number of samples of a given class that will be used in training. Use a value of 0 to impose no limit. No limit is the default, but this function can be called with 0 to unset a previous setting, for example to cancel the class cap for testing after using it in training.
|
|
Set up a file destination for storing graphical confusion matrices at the conclusion of a test. This output is available during test operations.
|
|
Accessor method.
|
|
Set up a file destination for storing sample labels. As samples are routinely submitted in randomized order, this is the only way of knowing after the fact which labels go with which predictions. A single label is written per line, each corresponding to a test sample. This output is available during test operations.
|
|
Sets the DimList, that is, the features to use for training/testing. The classifier model instances are recreated, as the input features are a basic aspect of the model architecture. This is done via calls to deleteClassifiers() and newClassifiers().
|
|
Accessor method.
|
|
Setting the labelChoiceType defines what to do during training when multiple labels are available, and class capping is turned on. If class capping is not active, then all training protocols are the same. In general, if multiple labels are available for a sample, one or more of them are chosen for training according to the training protocol. Since the runtime capping of classes can bias the sampling towards the first samples encountered, the data should always be presented in random order when using class capping. More specifically:
|
|
Set up a file destination for storing sample label vectors. This is useful in multiple-label situations. One vector of floating point values is written per line, each corresponding to a test sample. For example, the vector ( 0.5 0.5 0 0 0 0 ) indicates that a sample is labeled as belonging to the first and second classes. This output is available during test operations.
|
|
Sets the number of training epochs, that is, the number of times the training set will be presented.
|
|
Sets the number of voters, i.e. , the number classifier model instances. If CV mode is in effect, the number of voters is multiplied by the number of views in the ViewSet. This adjustment is preceded by a call to deleteClassifiers() and followed by a call to newClassifiers().
|
|
Set up a file destination for storing output predictions. These single-class predictions are contrast-enhanced derivations of the distributed prediction vector (winner-take-all). If more than one class label is tied to be the winner, then the label -1 is written. This output is available during test and classify operations.
|
|
Set up a file destination for storing distributed prediction vectors, one per sample. This output is available during test and classify operations.
|
|
Set up a file destination for storing graphical decision surfaces, as generated by the predPpm() method. This output is available during train and test operations. More details are available in predPpm().
|
|
Tests the classifier based on the samples in the ViewSet, that is, generate a prediction as to the class label of each sample. If CvMode is set, then each View object is submitted to a separate classifier model instance for cross-validated testing. If not cross-validating, then a single instance generates the predictions for all the samples. Starts by resetting all entry count and class statistics counters, and generates any requested stream outputs as part of the process of running the test.
|
|
Generates a thematic map, that is, one where a pixel's color indicates the predicted class for that pixel. To tell what the colors mean, a legend can be generated via Palette::writeLegend().
|
|
Trains the classifier using the samples in the ViewSet object. If CvMode is set, then training is cross-validated, creating one set of classifier model instances per View in the ViewSet. If not cross-validating, then each of the Views in the ViewSet is used to train the classifier in turn. If using class-capping, then training alternates between views, so that not all samples are drawn from the first View. When done, invokes predPpm() if this was requested via setPredPpmStream(). Also, starts out by resetting entry counts and class statistics counters.
|