iRoCS Toolbox  1.1.0
Public Types | Public Member Functions
svt::CrossValidator< FV, SVMTYPE, PROBLEM > Class Template Reference

The CrossValidator class provides a highly optimized cross validation algorithm. More...

#include <CrossValidator.hh>

Collaboration diagram for svt::CrossValidator< FV, SVMTYPE, PROBLEM >:

Public Types

typedef FV FV_TYPE
 
typedef SVMTYPE::template Traits< FV >::ModelType ModelType
 
typedef PROBLEM PROBLEM_TYPE
 

Public Member Functions

 CrossValidator (SVMTYPE *svm=0)
 
 ~CrossValidator ()
 
double classificationDelta () const
 
const std::vector< StDataASCII > & classificationDetailsByUID () const
 get classification details for each uid from last full CV or parital CV. More...
 
void clearKernelCache ()
 call clearKernelCache() of selected svm. More...
 
int doFullCV (const std::vector< int > &subsetIndexByUID, std::vector< double > &predictedClassLabelByUID)
 do a full cross validation. More...
 
int doPartialCV (int subsetIndex, const std::vector< int > &subsetIndexByUID, std::vector< double > &predictedClassLabelByUID, ModelType *partialModel=0)
 Do one part of a cross validation. More...
 
const ModelTypefullModel () const
 
bool getStoreClassificationDetailsFlag () const
 
template<typename STDATA >
void loadParameters (STDATA &stData)
 
void preprocessTrainingData ()
 trains all two-class SVM's with the whole data set. More...
 
template<typename STDATA >
void saveParameters (STDATA &stData)
 
template<typename STDATA >
void saveStatistics (STDATA &statistics, int detailLevel=1)
 save cross validation statistics. More...
 
void setClassificationDelta (double d)
 
void setProgressReporter (ProgressReporter *pr)
 
void setStoreClassificationDetailsFlag (bool f)
 
void setTrainingData (const PROBLEM *problem)
 set the training data. More...
 
SVMTYPE * svm ()
 
const PROBLEM * trainingData () const
 get pointer to training data, that was set with setTrainingData(). More...
 
void updateKernelCache ()
 call updateKernelCache() of selected svm with given problem. More...
 

Detailed Description

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
class svt::CrossValidator< FV, SVMTYPE, PROBLEM >

The CrossValidator class provides a highly optimized cross validation algorithm.

In a first step the SVM's for the full data set are trained and in the following steps only those SVM's are retrained, for which one or more of the left out vectors where support vectors. For this the given SVM class must provide a method retrainWithLeftOutVectors( trainData, fullModel, leaveOutFlagByUID, resultingModel)

The template parameters are the following:

Parameters
FVfeature vector class, e.g. BasicFV
SVMTYPESVM class, could be any one-class, two-class or multi-class SVMe.g. MultiClassSVMOneVsOne< TwoClassSVMc< Kernel_LINEAR> >
PROBLEMcontainer for your training data, e.g. GroupedTrainingData or SVM_Problem (which is considerably slower with multi-class SVM's)

To use it, do the following steps:

Definition at line 115 of file CrossValidator.hh.

Member Typedef Documentation

◆ ModelType

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
typedef SVMTYPE::template Traits<FV>::ModelType svt::CrossValidator< FV, SVMTYPE, PROBLEM >::ModelType

Definition at line 124 of file CrossValidator.hh.

◆ FV_TYPE

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
typedef FV svt::CrossValidator< FV, SVMTYPE, PROBLEM >::FV_TYPE

Definition at line 125 of file CrossValidator.hh.

◆ PROBLEM_TYPE

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
typedef PROBLEM svt::CrossValidator< FV, SVMTYPE, PROBLEM >::PROBLEM_TYPE

Definition at line 126 of file CrossValidator.hh.

Constructor & Destructor Documentation

◆ CrossValidator()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
svt::CrossValidator< FV, SVMTYPE, PROBLEM >::CrossValidator ( SVMTYPE *  svm = 0)
inline

◆ ~CrossValidator()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
svt::CrossValidator< FV, SVMTYPE, PROBLEM >::~CrossValidator ( )
inline

Definition at line 148 of file CrossValidator.hh.

Member Function Documentation

◆ svm()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
SVMTYPE* svt::CrossValidator< FV, SVMTYPE, PROBLEM >::svm ( )
inline

Definition at line 164 of file CrossValidator.hh.

◆ setProgressReporter()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::setProgressReporter ( ProgressReporter pr)
inline

Definition at line 169 of file CrossValidator.hh.

◆ setTrainingData()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::setTrainingData ( const PROBLEM *  problem)
inline

set the training data.

the CrossValidator only stores a pointer to it, so you are responsible that the training data keeps avaiblibe during further calls, and is deleted at the end of the program

Parameters
problempointer to the training data

Definition at line 187 of file CrossValidator.hh.

◆ trainingData()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
const PROBLEM* svt::CrossValidator< FV, SVMTYPE, PROBLEM >::trainingData ( ) const
inline

get pointer to training data, that was set with setTrainingData().

Returns
pointer to training data or 0, if no training data was specified yet

Definition at line 200 of file CrossValidator.hh.

◆ updateKernelCache()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::updateKernelCache ( )
inline

call updateKernelCache() of selected svm with given problem.

You are responsible to call this before preprocessTrainingData(), every time when kernel parameters or dataset was chenged. (usually every time before you call preprocessTrainingData())

Parameters

Definition at line 221 of file CrossValidator.hh.

◆ clearKernelCache()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::clearKernelCache ( )
inline

call clearKernelCache() of selected svm.

Parameters

Definition at line 240 of file CrossValidator.hh.

◆ preprocessTrainingData()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::preprocessTrainingData ( )
inline

trains all two-class SVM's with the whole data set.

This must be done before calling doFullCV() of doPartialCV(). If Kernel_MATRIX is used, you must call updateKernelCache() before

Definition at line 256 of file CrossValidator.hh.

◆ doFullCV()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
int svt::CrossValidator< FV, SVMTYPE, PROBLEM >::doFullCV ( const std::vector< int > &  subsetIndexByUID,
std::vector< double > &  predictedClassLabelByUID 
)

do a full cross validation.

Just calls doPartialCV() for each subset index and collects the results. See there for the preconditions

Parameters
subsetIndexByUIDtells for each feature vector (identified by its uniqueID) to which subset it belongs. If the uniqueIDs of your feature vectors are consecutive numbers from 0...nFeatureVectors-1, then you can create this array with generateSortedSubsets() or generateShuffledSubsets()
predictedClassLabelByUID(output) stores the predicted class label for each feature vector. Will be resized to same size as subsetIndexByUID
Returns
total number of correct classifications

Referenced by svt::CrossValidator< FV, SVMTYPE, PROBLEM >::preprocessTrainingData().

◆ doPartialCV()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
int svt::CrossValidator< FV, SVMTYPE, PROBLEM >::doPartialCV ( int  subsetIndex,
const std::vector< int > &  subsetIndexByUID,
std::vector< double > &  predictedClassLabelByUID,
ModelType partialModel = 0 
)

Do one part of a cross validation.

The training data must already be given with setTrainingData() and processed with preprocessTrainingData(). The segmentation into the subsets 0...n must be given in subsetIndexByUID, where the membership for each feature vector is defined. To compare, wether the predicted Label is equal to the original label, the classificationDelta is used (you can change it with setClassificationDelta())

this method may be called from multiple threads to speed up the calculation

Parameters
subsetIndexindex of the subset, that shall be left out for training and be used for classification
subsetIndexByUIDtells for each feature vector (identified by its uniqueID) to wich subset it belongs. If the uniqueIDs of your feature vectors are consecutive numbers from 0...nFeatureVectors-1, then you can create this array with generateSortedSubsets() or generateShuffledSubsets()
predictedClassLabelByUID(output) stores the predicted class label for each feature vector in test-subset. Must have same size as subsetIndexByUID.
partialModelpointer to existing model object: Will be passed to _svm->retrainWithLeftOutVectors() or 0: allocate tempoarary model for this purpose
Returns
total number of correct classifications

Referenced by svt::CrossValidator< FV, SVMTYPE, PROBLEM >::preprocessTrainingData().

◆ fullModel()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
const ModelType& svt::CrossValidator< FV, SVMTYPE, PROBLEM >::fullModel ( ) const
inline

Definition at line 352 of file CrossValidator.hh.

◆ setClassificationDelta()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::setClassificationDelta ( double  d)
inline

Definition at line 357 of file CrossValidator.hh.

◆ classificationDelta()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
double svt::CrossValidator< FV, SVMTYPE, PROBLEM >::classificationDelta ( ) const
inline

Definition at line 362 of file CrossValidator.hh.

◆ setStoreClassificationDetailsFlag()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::setStoreClassificationDetailsFlag ( bool  f)
inline

Definition at line 368 of file CrossValidator.hh.

◆ getStoreClassificationDetailsFlag()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
bool svt::CrossValidator< FV, SVMTYPE, PROBLEM >::getStoreClassificationDetailsFlag ( ) const
inline

Definition at line 373 of file CrossValidator.hh.

◆ saveStatistics()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
template<typename STDATA >
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::saveStatistics ( STDATA &  statistics,
int  detailLevel = 1 
)
inline

save cross validation statistics.

Parameters
statisticsstructured data, where to store the statistics
detailLevel0: nothing, 1: training statistics from last call to doFullCV()

Definition at line 391 of file CrossValidator.hh.

◆ classificationDetailsByUID()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
const std::vector< StDataASCII>& svt::CrossValidator< FV, SVMTYPE, PROBLEM >::classificationDetailsByUID ( ) const
inline

get classification details for each uid from last full CV or parital CV.

Use setStoreClassificationDetailsFlag() before preprocessTrainingData() to enable storage of these infos during cross validation

Returns
vector with classification details for each UID

Definition at line 415 of file CrossValidator.hh.

◆ loadParameters()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
template<typename STDATA >
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::loadParameters ( STDATA &  stData)
inline

Definition at line 423 of file CrossValidator.hh.

◆ saveParameters()

template<typename FV, typename SVMTYPE, typename PROBLEM = GroupedTrainingData<FV>>
template<typename STDATA >
void svt::CrossValidator< FV, SVMTYPE, PROBLEM >::saveParameters ( STDATA &  stData)
inline

Definition at line 433 of file CrossValidator.hh.


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