iRoCS Toolbox  1.1.0
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
svt::MultiClassSVMOneVsRest< SVM > Class Template Reference

The MultiClassSVMOneVsRest class provides a one vs. More...

#include <MultiClassSVMOneVsRest.hh>

Collaboration diagram for svt::MultiClassSVMOneVsRest< SVM >:

Data Structures

struct  DecisionValueAndLabel
 
class  DummyResultVector
 
struct  Traits
 

Public Types

typedef std::vector< double > DetailedResultType
 

Public Member Functions

 MultiClassSVMOneVsRest (const SVM &svm)
 Create a multi class SVM basing on the given "two-class-SVM", using the One versus Rest algorithm. More...
 
 MultiClassSVMOneVsRest ()
 
template<typename FV , typename ResultVector >
double classify (const FV &testObject, const typename Traits< FV >::ModelType &model, ResultVector &resultVector) const
 classify the given testObject using the model More...
 
template<typename FV >
double classify (const FV &testObject, const typename Traits< FV >::ModelType &model) const
 classify the given testObject using the model More...
 
void clearKernelCache () const
 call the clearKernelCache() method of selected two-class svm More...
 
template<typename STDATA >
void loadParameters (STDATA &stData)
 
template<typename FV , typename ResultVector >
unsigned int predictClassIndex (const FV &testObject, const typename Traits< FV >::ModelType &model, ResultVector &resultVector) const
 classify the given testObject using the model More...
 
template<typename FV >
unsigned int predictClassIndex (const FV &testObject, const typename Traits< FV >::ModelType &model) const
 classify the given testObject using the model More...
 
template<typename FV >
void retrainWithLeftOutVectors (const GroupedTrainingData< FV > &trainData, const typename Traits< FV >::ModelType &fullModel, const std::vector< char > &leaveOutFlagsByUID, typename Traits< FV >::ModelType &resultingModel) const
 calls the retrainWithLeftOutVectors() for each two-class model, only if the model is affected by the left out vectors More...
 
template<typename ModelType , typename STDATA >
void saveClassificationDetails (const ModelType &model, const DetailedResultType &resultVector, STDATA &stData) const
 save classification details. More...
 
template<typename STDATA >
void saveParameters (STDATA &stData) const
 
void setProgressReporter (ProgressReporter *pr)
 set a progress reporter object. More...
 
template<typename FV >
void train (const GroupedTrainingData< FV > &trainData, typename Traits< FV >::ModelType &model) const
 train SVM with given Feature Vectors. More...
 
template<typename FV >
void train (const SVM_Problem< FV > &problem, typename Traits< FV >::ModelType &model) const
 train SVM with given Feature Vectors. More...
 
template<typename ForwardIter >
void train (ForwardIter FV_begin, const ForwardIter &FV_end, typename Traits< typename std::iterator_traits< ForwardIter >::value_type >::ModelType &model) const
 train the Multi Class SVM with the given feature vectors. More...
 
template<typename ForwardIter , typename Accessor >
void train (ForwardIter FV_begin, const ForwardIter &FV_end, typename Traits< typename Accessor::template Traits< ForwardIter >::value_type >::ModelType &model, Accessor accessor) const
 same as train(), but you can specify an Accessor for accessing the elements of your container. More...
 
const SVM & twoClassSVM () const
 (description) More...
 
SVM & twoClassSVM ()
 
template<typename ForwardIter , typename Accessor >
void updateKernelCache (const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor) const
 call the updateKernelCache() method of selected two-class svm More...
 

Static Public Member Functions

static const char * description ()
 
static void getParamInfos (std::vector< ParamInfo > &)
 get information about the parameters, that are used in loadParameters() and saveParameters(). More...
 
static const char * name ()
 

Detailed Description

template<typename SVM>
class svt::MultiClassSVMOneVsRest< SVM >

The MultiClassSVMOneVsRest class provides a one vs.

rest multi class algorithm

Parameters
SVMa two-class-svm

Definition at line 140 of file MultiClassSVMOneVsRest.hh.

Member Typedef Documentation

◆ DetailedResultType

template<typename SVM >
typedef std::vector<double> svt::MultiClassSVMOneVsRest< SVM >::DetailedResultType

Definition at line 152 of file MultiClassSVMOneVsRest.hh.

Constructor & Destructor Documentation

◆ MultiClassSVMOneVsRest() [1/2]

template<typename SVM >
svt::MultiClassSVMOneVsRest< SVM >::MultiClassSVMOneVsRest ( const SVM &  svm)
inline

Create a multi class SVM basing on the given "two-class-SVM", using the One versus Rest algorithm.

The two class SVM may be either one of svt::TwoClassSVMc, or svt::TwoClassSVMnu or your own SVM implementation, which fulfills the following interface: SVM::train( ITER fvs_begin, ITER fvs_end, MODEL& model); ...

Todo:
complete this
Parameters
svmTwo-Class Support vector maschine
Exceptions

Definition at line 206 of file MultiClassSVMOneVsRest.hh.

◆ MultiClassSVMOneVsRest() [2/2]

template<typename SVM >
svt::MultiClassSVMOneVsRest< SVM >::MultiClassSVMOneVsRest ( )
inline

Definition at line 213 of file MultiClassSVMOneVsRest.hh.

Member Function Documentation

◆ setProgressReporter()

template<typename SVM >
void svt::MultiClassSVMOneVsRest< SVM >::setProgressReporter ( ProgressReporter pr)
inline

set a progress reporter object.

Every time any progress is made in the training or classification, the reportProgress() method of this object is callled.

Parameters
prpointer to an object with a child class of ProgressReporter or 0, if you don't want any more progress reporting. You are responsible, that your ProgressReporter object is not deleted during operation of MultiClassSVMOneVsOne

Definition at line 232 of file MultiClassSVMOneVsRest.hh.

◆ twoClassSVM() [1/2]

template<typename SVM >
const SVM& svt::MultiClassSVMOneVsRest< SVM >::twoClassSVM ( ) const
inline

(description)

Parameters

Definition at line 251 of file MultiClassSVMOneVsRest.hh.

◆ twoClassSVM() [2/2]

template<typename SVM >
SVM& svt::MultiClassSVMOneVsRest< SVM >::twoClassSVM ( )
inline

Definition at line 256 of file MultiClassSVMOneVsRest.hh.

◆ updateKernelCache()

template<typename SVM >
template<typename ForwardIter , typename Accessor >
void svt::MultiClassSVMOneVsRest< SVM >::updateKernelCache ( const ForwardIter &  fvBegin,
const ForwardIter &  fvEnd,
Accessor  accessor 
) const
inline

call the updateKernelCache() method of selected two-class svm

Parameters

Definition at line 274 of file MultiClassSVMOneVsRest.hh.

◆ clearKernelCache()

template<typename SVM >
void svt::MultiClassSVMOneVsRest< SVM >::clearKernelCache ( ) const
inline

call the clearKernelCache() method of selected two-class svm

Parameters

Definition at line 293 of file MultiClassSVMOneVsRest.hh.

◆ train() [1/4]

template<typename SVM >
template<typename FV >
void svt::MultiClassSVMOneVsRest< SVM >::train ( const GroupedTrainingData< FV > &  trainData,
typename Traits< FV >::ModelType &  model 
) const

train SVM with given Feature Vectors.

(raw interface)

this is the basic method, all others will call this one

Parameters
trainDataStructure with pointers to feature-vectors
model(output) model containing a vector of trained of TwoClassModels. It stores only pointers to the feature vectors, but you still own them!

Definition at line 96 of file MultiClassSVMOneVsRest.hh.

Referenced by svt::MultiClassSVMOneVsRest< SVM >::clearKernelCache(), and svt::MultiClassSVMOneVsRest< SVM >::train().

◆ train() [2/4]

template<typename SVM >
template<typename FV >
void svt::MultiClassSVMOneVsRest< SVM >::train ( const SVM_Problem< FV > &  problem,
typename Traits< FV >::ModelType &  model 
) const
inline

train SVM with given Feature Vectors.

(general SVM interface)

Parameters
problemStructure with pointers to feature-vectors and y's
model(output) model containing a triangular matrix of trained of TwoClassModels. It stores only pointers to the feature vectors, but you still own them!

Definition at line 328 of file MultiClassSVMOneVsRest.hh.

◆ train() [3/4]

template<typename SVM >
template<typename ForwardIter >
void svt::MultiClassSVMOneVsRest< SVM >::train ( ForwardIter  FV_begin,
const ForwardIter &  FV_end,
typename Traits< typename std::iterator_traits< ForwardIter >::value_type >::ModelType &  model 
) const
inline

train the Multi Class SVM with the given feature vectors.

The FeatureVector-Container must contain the Feature vectors directly, e.g., std::vector<MyFeatureVec>.

Parameters
FV_beginiterator to the first element of your FeatureVector-Container
FV_enditerator to one past the last element of your FeatureVector-Container
model(output) model containing a triangular matrix of trained of TwoClassModels. It stores only pointers to the feature vectors, but you still own them!
Exceptions

Definition at line 355 of file MultiClassSVMOneVsRest.hh.

◆ train() [4/4]

template<typename SVM >
template<typename ForwardIter , typename Accessor >
void svt::MultiClassSVMOneVsRest< SVM >::train ( ForwardIter  FV_begin,
const ForwardIter &  FV_end,
typename Traits< typename Accessor::template Traits< ForwardIter >::value_type >::ModelType &  model,
Accessor  accessor 
) const
inline

same as train(), but you can specify an Accessor for accessing the elements of your container.

This accessor must return a reference to the corresponding feature vector. Use DirectAccessor for containers like std::vector<FV> and DereferencingAccessor for containers like std::vector<FV*>

Parameters
FVP_beginiterator to the first element of your PointerToFeatureVector-Container
FVP_enditerator to one past the last element of your PointerToFeatureVector-Container
model(output) model containing a triangular matrix of trained of TwoClassModels. It stores only pointers to the feature vectors, but you still own them!
accessorfunctor, which accesses the feature vector in the container
Exceptions

Definition at line 386 of file MultiClassSVMOneVsRest.hh.

◆ retrainWithLeftOutVectors()

template<typename SVM >
template<typename FV >
void svt::MultiClassSVMOneVsRest< SVM >::retrainWithLeftOutVectors ( const GroupedTrainingData< FV > &  trainData,
const typename Traits< FV >::ModelType &  fullModel,
const std::vector< char > &  leaveOutFlagsByUID,
typename Traits< FV >::ModelType &  resultingModel 
) const

calls the retrainWithLeftOutVectors() for each two-class model, only if the model is affected by the left out vectors

Parameters
trainDataStructure with pointers to feature-vectors must be identical to training data set that was used to train the fullModel
fullModelmodel that was trained using complete training data set without leaving out anything
leaveOutFlagsByUIDleave out flag for each feature vector, accessed via its uniqueID (true means leave this vector out from training)
resultingModel(output) model containing a triangular matrix of trained of TwoClassModels. It stores only pointers to the feature vectors, but you still own them!

Definition at line 220 of file MultiClassSVMOneVsRest.hh.

Referenced by svt::MultiClassSVMOneVsRest< SVM >::train().

◆ predictClassIndex() [1/2]

template<typename SVM >
template<typename FV , typename ResultVector >
unsigned int svt::MultiClassSVMOneVsRest< SVM >::predictClassIndex ( const FV &  testObject,
const typename Traits< FV >::ModelType &  model,
ResultVector &  resultVector 
) const

classify the given testObject using the model

Parameters
testObjectthe test object
modelthe model
[out]resultVectorresults (decision values) from the two-class classifications. resultVector will be resized properly. The type could be the typedef'ed DetailedResultType or your own resultVector class.
Returns
classIndex of winning class

Definition at line 407 of file MultiClassSVMOneVsRest.hh.

Referenced by svt::MultiClassSVMOneVsRest< SVM >::classify(), svt::MultiClassSVMOneVsRest< SVM >::predictClassIndex(), and svt::MultiClassSVMOneVsRest< SVM >::train().

◆ predictClassIndex() [2/2]

template<typename SVM >
template<typename FV >
unsigned int svt::MultiClassSVMOneVsRest< SVM >::predictClassIndex ( const FV &  testObject,
const typename Traits< FV >::ModelType &  model 
) const
inline

classify the given testObject using the model

Parameters
testObjectthe test object
modelthe model
Returns
classIndex of winning class

Definition at line 458 of file MultiClassSVMOneVsRest.hh.

◆ classify() [1/2]

template<typename SVM >
template<typename FV , typename ResultVector >
double svt::MultiClassSVMOneVsRest< SVM >::classify ( const FV &  testObject,
const typename Traits< FV >::ModelType &  model,
ResultVector &  resultVector 
) const
inline

classify the given testObject using the model

Parameters
testObjectthe test object
modelthe model
[out]resultVectorresults (decision values) from the two-class classifications. resultVector will be resized properly. The type could be the typedef'ed DetailedResultType or your own resultVector class.
Returns
label of winning class

Definition at line 482 of file MultiClassSVMOneVsRest.hh.

Referenced by svt::MultiClassSVMOneVsRest< SVM >::classify().

◆ classify() [2/2]

template<typename SVM >
template<typename FV >
double svt::MultiClassSVMOneVsRest< SVM >::classify ( const FV &  testObject,
const typename Traits< FV >::ModelType &  model 
) const
inline

classify the given testObject using the model

Parameters
testObjectthe test object
modelthe model
Returns
label of winning class

Definition at line 501 of file MultiClassSVMOneVsRest.hh.

◆ loadParameters()

template<typename SVM >
template<typename STDATA >
void svt::MultiClassSVMOneVsRest< SVM >::loadParameters ( STDATA &  stData)
inline

Definition at line 510 of file MultiClassSVMOneVsRest.hh.

◆ saveParameters()

template<typename SVM >
template<typename STDATA >
void svt::MultiClassSVMOneVsRest< SVM >::saveParameters ( STDATA &  stData) const
inline

Definition at line 517 of file MultiClassSVMOneVsRest.hh.

◆ saveClassificationDetails()

template<typename SVM >
template<typename ModelType , typename STDATA >
void svt::MultiClassSVMOneVsRest< SVM >::saveClassificationDetails ( const ModelType &  model,
const DetailedResultType resultVector,
STDATA &  stData 
) const
inline

save classification details.

Here the ordered labels as "labels" and the according decision values as "dec_values"

Parameters
modelthe used model
resultVectorresults from the classification
stDatastructured data, where to store the details

Definition at line 536 of file MultiClassSVMOneVsRest.hh.

◆ getParamInfos()

template<typename SVM >
static void svt::MultiClassSVMOneVsRest< SVM >::getParamInfos ( std::vector< ParamInfo > &  )
inlinestatic

get information about the parameters, that are used in loadParameters() and saveParameters().

The Infos are appended to the passed array

Parameters
parray of ParamInfos. The Infos will be appended to this array

Definition at line 580 of file MultiClassSVMOneVsRest.hh.

◆ name()

template<typename SVM >
static const char* svt::MultiClassSVMOneVsRest< SVM >::name ( )
inlinestatic

◆ description()

template<typename SVM >
static const char* svt::MultiClassSVMOneVsRest< SVM >::description ( )
inlinestatic

Definition at line 589 of file MultiClassSVMOneVsRest.hh.


The documentation for this class was generated from the following file: