Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

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

#include <Sample.h>

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

Object List of all members.

Detailed Description

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

A template for a sample.

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:

That is to say, the class must be defined about like this:
 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.

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.

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.

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.

_trueClass
 The true (known) class for this sample.

_classification
 The classification for this sample.

_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)


Constructor & Destructor Documentation

template<class T, class I = std::string, class C = int>
prapi::Sample< T, I, C >::Sample   trueClass = -1 [inline]
 

Create a new sample.

Parameters:
trueClass  the true class of the sample. The default value (-1) means not defined.

template<class T, class I = std::string, class C = int>
prapi::Sample< T, I, C >::Sample const List< T > &    features,
  trueClass = -1
[inline]
 

Create a new sample.

Parameters:
features  A feature vector for the sample.
trueClass  the true class of the sample. The default value (-1) means not defined.


Member Function Documentation

template<class T, class I = std::string, class C = int>
const List<T>& prapi::Sample< T, I, C >::featureVector void    const [inline]
 

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.

template<class T, class I = std::string, class C = int>
List<T>& prapi::Sample< T, I, C >::featureVector void    [inline]
 

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.

template<class T, class I = std::string, class C = int>
List<T> prapi::Sample< T, I, C >::getFeatureVector void    const [inline]
 

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.

template<class T, class I = std::string, class C = int>
I prapi::Sample< T, I, C >::getIdentifier void    const [inline]
 

Get the identifier of this sample.

The identifier provides means to distinguish between different samples of any type.

template<class T, class I = std::string, class C = int>
const I& prapi::Sample< T, I, C >::identifier void    const [inline]
 

Get the identifier of this sample.

The identifier provides means to distinguish between different samples of any type.

template<class T, class I = std::string, class C = int>
I& prapi::Sample< T, I, C >::identifier void    [inline]
 

Get the identifier of this sample.

The identifier provides means to distinguish between different samples of any type.

template<class T, class I, class C>
template<class U, class V, class W>
prapi::Sample< T, I, C >::operator Sample< U, V, W >  
 

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.

template<class T, class I, class C>
template<class U, class V, class W>
Sample< T, I, C > & prapi::Sample< T, I, C >::operator= const Sample< U, V, W > &    other
 

Copy the contents of another sample and perform a simultaneous typecast.

See the typecast operator for more information.

template<class T, class I, class C>
void prapi::Sample< T, I, C >::print std::ostream &    sout,
const List< std::string > &    classList
 

Pretty-print the contents of a sample to a stream.

Parameters:
sout  the output stream
classList  names for the classes a sample may belong to


Friends And Related Function Documentation

template<class T, class I = std::string, class C = int>
template<class U, class V, class W>
bool operator!= const Sample< U, V, W > &    smpl1,
const Sample< U, V, W > &    smpl2
[friend]
 

Compare two samples.

Samples are defined to be different if their identifiers are different.

template<class T, class I = std::string, class C = int>
template<class U, class V, class W>
bool operator== const Sample< U, V, W > &    smpl1,
const Sample< U, V, W > &    smpl2
[friend]
 

Compare two samples.

Samples are defined to be equal if their identifiers are equal.


Member Data Documentation

template<class T, class I = std::string, class C = int>
I prapi::Sample< T, I, C >::_identifier [protected]
 

The identifier used to distinguish between samples.

Typically a string.


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.