iRoCS Toolbox
1.1.0
|
The CrossValidator class provides a highly optimized cross validation algorithm. More...
#include <CrossValidator.hh>
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 ModelType & | fullModel () 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... | |
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:
FV | feature vector class, e.g. BasicFV |
SVMTYPE | SVM class, could be any one-class, two-class or multi-class SVMe.g. MultiClassSVMOneVsOne< TwoClassSVMc< Kernel_LINEAR> > |
PROBLEM | container 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.
typedef SVMTYPE::template Traits<FV>::ModelType svt::CrossValidator< FV, SVMTYPE, PROBLEM >::ModelType |
Definition at line 124 of file CrossValidator.hh.
typedef FV svt::CrossValidator< FV, SVMTYPE, PROBLEM >::FV_TYPE |
Definition at line 125 of file CrossValidator.hh.
typedef PROBLEM svt::CrossValidator< FV, SVMTYPE, PROBLEM >::PROBLEM_TYPE |
Definition at line 126 of file CrossValidator.hh.
|
inline |
Definition at line 129 of file CrossValidator.hh.
Referenced by svt::CrossValidator< FV, SVMTYPE, PROBLEM >::~CrossValidator().
|
inline |
Definition at line 148 of file CrossValidator.hh.
|
inline |
Definition at line 164 of file CrossValidator.hh.
|
inline |
Definition at line 169 of file CrossValidator.hh.
|
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
problem | pointer to the training data |
Definition at line 187 of file CrossValidator.hh.
|
inline |
get pointer to training data, that was set with setTrainingData().
Definition at line 200 of file CrossValidator.hh.
|
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())
Definition at line 221 of file CrossValidator.hh.
|
inline |
call clearKernelCache() of selected svm.
Definition at line 240 of file CrossValidator.hh.
|
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.
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
subsetIndexByUID | tells 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 |
Referenced by svt::CrossValidator< FV, SVMTYPE, PROBLEM >::preprocessTrainingData().
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
subsetIndex | index of the subset, that shall be left out for training and be used for classification |
subsetIndexByUID | tells 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. |
partialModel | pointer to existing model object: Will be passed to _svm->retrainWithLeftOutVectors() or 0: allocate tempoarary model for this purpose |
Referenced by svt::CrossValidator< FV, SVMTYPE, PROBLEM >::preprocessTrainingData().
|
inline |
Definition at line 352 of file CrossValidator.hh.
|
inline |
Definition at line 357 of file CrossValidator.hh.
|
inline |
Definition at line 362 of file CrossValidator.hh.
|
inline |
Definition at line 368 of file CrossValidator.hh.
|
inline |
Definition at line 373 of file CrossValidator.hh.
|
inline |
save cross validation statistics.
statistics | structured data, where to store the statistics |
detailLevel | 0: nothing, 1: training statistics from last call to doFullCV() |
Definition at line 391 of file CrossValidator.hh.
|
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
Definition at line 415 of file CrossValidator.hh.
|
inline |
Definition at line 423 of file CrossValidator.hh.
|
inline |
Definition at line 433 of file CrossValidator.hh.