#include <Sample.h>
Inheritance diagram for prapi::Sample< T, I, C >:

A sample consists of a feature vector (of any type), and identifier and two classifications: the correct and the supposed one. The template parameters T, I and C indicate the type of the feature vector, the type of the indentifier and the type of the classifications, respectively.
The identifier is used to distinguish different samples. For an example, image samples could store the image name and coordinates as an identifier object. The default type for the identifier is string. And identifier object must have operator== defined in addition to the usual constructors and an assignment operator.
The rationale behind the type of the classification is somewhat more complicated. In most applications, the default type (int) works just fine and the application programmer can totally discard it. By default, the integer-typed classification represents a class index as such. If more sophisticated (e.g. fuzzy or probabilistic) classifications are needed, some non-primitive types must be used. The class used to indicate classification must provide the following services:
class MyClassification
{
public:
MyClassification(const MyClassification& other);
MyClassification(int classification = -1); //-1 means not defined
MyClassification& operator= (const MyClassification& other);
MyClassification& operator= (int classification);
operator int() { return classificationSomehowConvertedToClassIndex; }
};
Public Methods | |
| Sample (C trueClass=-1) | |
| Create a new sample. | |
| Sample (const List< T > &features, C trueClass=-1) | |
| Create a new sample. | |
| Sample (const Sample &other) | |
| Copy a sample. | |
| template<class U, class V, class W> | Sample (const Sample< U, V, W > &other) |
| Copy a sample and perform a simultaneous typecast. | |
| Sample & | operator= (const Sample &other) |
| Replace the contents of this sample. | |
| List< T > | getFeatureVector (void) const |
| Get the feature vector. | |
| List< T > & | featureVector (void) |
| Get the feature vector. | |
| const List< T > & | featureVector (void) const |
| Get the feature vector. | |
| void | setFeatureVector (const List< T > &vec) |
| Set the feature vector. | |
| C & | trueClass (void) |
| Get the true (known) class for this sample. | |
| C | getTrueClass (void) const |
| Get the true (known) class for this sample. | |
| void | setTrueClass (C classification) |
| Set the true (known) class for this sample. | |
| C & | classification (void) |
| Get the classification of this sample. | |
| C | getClassification (void) const |
| Get the classification of this sample. | |
| void | setClassification (C classification) |
| Set the classification of this sample. | |
| I & | identifier (void) |
| Get the identifier of this sample. | |
| const I & | identifier (void) const |
| Get the identifier of this sample. | |
| I | getIdentifier (void) const |
| Get the identifier of this sample. | |
| void | setIdentifier (const I &identifier) |
| Set the identifier of this sample. | |
| void | print (std::ostream &sout, const List< std::string > &classList) |
| Pretty-print the contents of a sample to a stream. | |
| template<class U, class V, class W> | operator Sample () |
| Typecast a sample to another type. | |
| template<class U, class V, class W> Sample & | operator= (const Sample< U, V, W > &other) |
| Copy the contents of another sample and perform a simultaneous typecast. | |
Static Public Methods | |
| void | print (const List< Sample > &samples, std::ostream &sout, const List< std::string > &classList) |
| Pretty-print all samples in a list. | |
Protected Attributes | |
| List< T > | _lstFeatureVector |
| The feature vector for this sample. | |
| C | _trueClass |
| The true (known) class for this sample. | |
| C | _classification |
| The classification for this sample. | |
| I | _identifier |
| The identifier used to distinguish between samples. | |
Friends | |
| template<class U, class V, class W> bool | operator== (const Sample< U, V, W > &smpl1, const Sample< U, V, W > &smpl2) |
| Compare two samples. | |
| template<class U, class V, class W> bool | operator!= (const Sample< U, V, W > &smpl1, const Sample< U, V, W > &smpl2) |
| Compare two samples. | |
| template<class U, class V, class W> std::ostream & | operator<< (std::ostream &sout, const Sample< U, V, W > &smpl) |
| template<class U, class V, class W> std::istream & | operator>> (std::istream &sin, Sample< U, V, W > &smpl) |
| template<class U, class V, class W> std::istream & | oldRead (std::istream &sin, Sample< U, V, W > &smpl) |
|
||||||||||
|
Create a new sample.
|
|
||||||||||||||||
|
Create a new sample.
|
|
||||||||||
|
Get the feature vector. The feature vector can contain any values. It may hold an integer-valued histogram, a continuous-valued multi-dimensional distribution or anything else. |
|
||||||||||
|
Get the feature vector. The feature vector can contain any values. It may hold an integer-valued histogram, a continuous-valued multi-dimensional distribution or anything else. |
|
||||||||||
|
Get the feature vector. The feature vector can contain any values. It may hold an integer-valued histogram, a continuous-valued multi-dimensional distribution or anything else. |
|
||||||||||
|
Get the identifier of this sample. The identifier provides means to distinguish between different samples of any type. |
|
||||||||||
|
Get the identifier of this sample. The identifier provides means to distinguish between different samples of any type. |
|
||||||||||
|
Get the identifier of this sample. The identifier provides means to distinguish between different samples of any type. |
|
|||||||||||||
|
Typecast a sample to another type.
The conversion will succeed only if the types of the feature vector, identifier and classification are typecastable to the wanted types. For example: Sample<double,string,int> smpl1; Sample<int,string,int> smpl2; Sample<double,ImageSampleIdentifier,int> smpl3; Sample<int,int,int> smpl4; smpl1 = (Sample<double,string,int>)smpl2; //valid smpl3 = (Sample<double,ImageSampleIdentifier,int)smpl1; //valid smpl2 = (Sample<int,string,int>)smpl4; //invalid! int is not typecastable to string Actually, the typecast operators in the previous examples are not necessary because the assignment operator makes automatic typecasts when possible. |
|
||||||||||||||
|
Copy the contents of another sample and perform a simultaneous typecast. See the typecast operator for more information. |
|
||||||||||||||||
|
Pretty-print the contents of a sample to a stream.
|
|
||||||||||||||||||||
|
Compare two samples. Samples are defined to be different if their identifiers are different. |
|
||||||||||||||||||||
|
Compare two samples. Samples are defined to be equal if their identifiers are equal. |
|
|||||
|
The identifier used to distinguish between samples. Typically a string. |