|
latest version v1.9 - last update 24 Nov 2005 |
|
#include <ltiClassificationStatistics.h>
Inheritance diagram for lti::classificationStatistics:


Public Types | |
| enum | eStatistics { CorrectSingle = -1, CorrectMultiple = -2, CorrectReject = -3, WrongSingle = -4, WrongMultiple = -5, WrongReject = -6, Error = -7 } |
Public Member Functions | |
| classificationStatistics () | |
| classificationStatistics (const parameters &par) | |
| ~classificationStatistics () | |
| bool | setParameters (const parameters ¶ms) |
| const parameters & | getParameters () const |
| eStatistics | consider (const classifier::outputVector &result, const int &realObjectID, const std::string &patternInfo="-?-") |
| void | reset () |
| void | flush () |
| bool | writeData (std::ostream &ostr) |
| bool | setNames (const std::map< int, std::string > &idMap) |
Data access members | |
Use these to access the internal data members | |
| const bool & | getSaved () const |
| const dynamicMatrix< double > & | getConfusionMatrix () const |
| const std::map< int, std::string > & | getIdToNamesMap () const |
Statistics access members | |
Use these to access the accumulated statistics | |
| const int & | getNumberOfResults () const |
| const int & | getCorrectSingle () const |
| const int & | getCorrectMultiple () const |
| const int & | getCorrectReject () const |
| const int & | getWrongSingle () const |
| const int & | getWrongMultiple () const |
| const int & | getWrongReject () const |
| const dynamicMatrix< double > & | getNBestMatrix () const |
| const dynamicMatrix< double > & | getNBestMultipleMatrix () const |
| const dynamicMatrix< double > & | getMinPlacesMatrix () const |
Static Public Member Functions | |
| static bool | loadNames (const std::string &filename, std::map< int, std::string > &idToNamesMap, const bool namesInFileFirst=false) |
Protected Member Functions | |
| bool | writeData () |
| bool | writeConfusionMatrix (std::ostream &out, const dynamicMatrix< double > &matrix) |
| bool | writeNBestMatrix (std::ostream &out, const dynamicMatrix< double > &matrix, const std::string &title, const bool &normalize, const std::string &labelSingular="Best", const std::string &labelPlural="Best") |
| bool | writeLogFileHeader (const std::string &filename) |
| bool | writeLogFile (const classifier::outputVector &result, const eStatistics &rState, const int &realObjectID, const std::string &patternInfo) |
| void | sortObjNames (const dynamicMatrix< double > &matrix, std::vector< int > &seqToRealId) |
| void | format (std::ostream &out, const int &width, const double &val) const |
| void | format (std::ostream &out, const int &width, const int &val) const |
| bool | inscribeObject (const std::string &name, const int &id) |
Protected Attributes | |
| parameters | param |
| bool | saved |
| dynamicMatrix< double > | confMatrix |
| std::map< int, std::string > | idToNamesMap |
Statistics | |
These are the internal members for storing the actual classification statistics | |
| int | numberOfResults |
| int | correctSingle |
| int | correctMultiple |
| int | correctReject |
| int | wrongSingle |
| int | wrongMultiple |
| int | wrongReject |
| dynamicMatrix< double > | nBest |
| dynamicMatrix< double > | nBestMultiple |
| dynamicMatrix< double > | minPlaces |
Static Protected Attributes | |
| static const int | logWidths [] |
| static const int | confWidths [] |
Classes | |
| class | parameters |
| the parameters for the class classificationStatistics More... | |
This object will generate some confusion matrices and log-files, which can help to the selection of classifier-parameters.
The results of the classification will be stored directly into the user specified files.
Following example shows how to use this object in the statistics for classification results.
lti::rbf theNet; // a rbf-Network // Training data set: // Some points in a two-dimensional feature-space will belong to one // of two classes: circle or square lti::dmatrix train(10,2); double trainData[20] = { 0, 3, // circle 1, 3, // circle 2, 3, // circle 0, 2, // circle 1, 2, // circle 2, 1, // square 3, 1, // square 4, 1, // square 3, 0, // square 4, 0};// square train.fill(trainData); // the ids for the patterns in the training set lti::ivector trainIds(10); int trainClasses[10] = {314,314,314,314,314,4,4,4,4,4}; trainIds.fill(trainClasses); // just to see what's happening when training... lti::streamProgressInfo progBox; theNet.setProgressObject(progBox); // train the classifier theNet.train(train,trainIds); // ------------- STATISTICS -------------- // prepare the statistics object lti::rbf::outputVector nnoutput; // output of the rbf network lti::classificationStatistics statistics; lti::classificationStatistics::parameters statParam; // all statistic files should be stored in the "tmp" directory statParam.path = "/tmp/"; // and of course, indicate the statistics-object which parameters // should be used: statistics.setParameters(statParam); // assign some human-readable names to the object-Ids std::map<int,std::string> names; names[314] = "Circle"; names[4] = "Square"; statistics.setNames(names); // now test some points of the 2D-feature space, and generate // some statistics about the classification: double x,y; // the coordinates of a point in the feature space int realID; // for the statistics is required the real id of // the given feature, to check if the classification is // correct or not! char buffer[1024]; // a temporary string buffer lti::dvector feature(2);// a feature-vector for (y=0;y<=4.0;y+=0.5) { for (x=0;x<=4.0;x+=0.5) { realID = (y>x) ? 314 : 4; // generate the real id! feature.at(0)=x; // initialize the feature vector feature.at(1)=y; theNet.classify(feature,nnoutput);// classify the vector! // generate a feature-name for the feature sprintf(buffer,"x: %.2f, y: %.2f",x,y); // consider the actual feature in the statistics statistics.consider(nnoutput,realID,buffer); } } statistics.flush(); // save all the statistics on disk!
Two files will be created: /tmp/logfile.txt with the list of the wrong classifications and /tmp/confusion.mat with the confusion matrices.
The confusion matrix file has following information:
--- Circle Square correctSingle correctMultip correctReject ... Circle 1.000 0.000 1.000000 0.000000 0.000000 ... Square 0.222 0.778 0.777778 0.000000 0.000000 ...
which means that the circle were allways correctly recognized, and the square was 22% wrong and 78% correctly classified.
|
|
|
default constructor
|
|
|
default constructor with parameters
|
|
|
Destructor.
|
|
||||||||||||||||
|
include a new classification result into the statistics. The patternInfo is additional text that will appear in the logFile. Returns the recognition state (see eStatistics). Note: the ID must be positive. negative indices are discarded. |
|
|
save all statistics stored by now into the file specified in the parameters. Note that the parameter writeConfusionMatrix must be set to true. |
|
||||||||||||||||
|
workaround for std::ios bug in gcc when writing double numbers
|
|
||||||||||||||||
|
workaround for std::ios bug in gcc when writing double numbers
|
|
|
returns a const reference to the confusion matrix
|
|
|
number of correct multiples
|
|
|
number of correct rejects
|
|
|
number of correct singles
|
|
|
returns a const reference to the idToNamesMap
|
|
|
minPlaces, i.e. minimum number of elements required in order to contain the proper class. |
|
|
nBest recognition results for single correct
|
|
|
nBest recognition results for multiple correct
|
|
|
returns a const reference to the number of results
|
|
|
returns a const reference to the parameters
|
|
|
returns a const reference to protected member "saved"
|
|
|
number of wrong multiples
|
|
|
number of wrong rejects
|
|
|
number of wrong singles
|
|
||||||||||||
|
use in the statistics an object with the given name and real id number
|
|
||||||||||||||||
|
load the file "filename", which contains the correspondences between a class id number and a class name. Note: calling this does NOT set the internal idToNamesMap!!! The file must consist of two columns. The first containing the object ids, the second the object names (optionally in double quotes) and separated by whitespaces e.g. 314 "Circle" 4 "Square"
|
|
|
reset clears the statistics
|
|
|
set the correspondences between a class id number and a class name.
|
|
|
set the parameters
|
|
||||||||||||
|
sort the object names in the matrices
|
|
||||||||||||
|
write confusion matrix to file
|
|
|
save all statistic data in the respective files
|
|
|
write all accumulated statistic data to the specified stream. this can be used to manually save the statistics. |
|
||||||||||||||||||||
|
write classification to file
|
|
|
write classification to file
|
|
||||||||||||||||||||||||||||
|
write nBest-matrix
|
|
|
the confusion matrix stores the classification results, each row represents one class (row index = realObjectID) and the classification results for this class
|
|
|
formatting widths for the columns of the confusion matrix file
|
|
|
number of correct multiples
|
|
|
number of correct rejects
|
|
|
number of correct singles
|
|
|
map an id number to the name of the object.
|
|
|
formatting widths for the columns of the log file
|
|
|
minPlaces, i.e. minimum number of elements required in order to contain the proper class. |
|
|
nBest recognition results for single correct
|
|
|
nBest recognition results for multiple correct
|
|
|
number of "consider(...)" called so far. Divide any value, e.g. correctSingle, by this to obtain recognition rates. |
|
|
store parameters
|
|
|
if true, all data has been saved. If false, some consider() have been called, and there are unsaved information. |
|
|
number of wrong multiples
|
|
|
number of wrong rejects
|
|
|
number of wrong singles
|