iRoCS Toolbox
1.1.0
|
#include <BasicSVMAdapterTempl.hh>
Public Member Functions | |
BasicSVMAdapterTempl () | |
virtual double | classify (const FV &testObject) |
classify the given Feature Vector. More... | |
double | classIndexToLabel (unsigned int classIndex) const |
map classIndex to label (loadModel() or train() must have been called before) More... | |
virtual void | clearKernelCache () |
call clearCache() method of selected kernel, e.g., for Kernel_MATRIX this will clear the internal cache matrix. More... | |
virtual void | computeTrainKernelMatrix (float **kmatrix, const std::vector< FV > &featureVectors) |
Evaluate kernel matrix of the svm. More... | |
bool | getStoreClassificationDetailsFlag () const |
FV * | getSupportVector (int i) const |
returns ith SV in model More... | |
std::vector< const typename svt::Model< FV > *> | getTwoClassModels () const |
returns vector containing pointers to all TwoClassModels More... | |
std::vector< typename svt::Model< FV > *> | getTwoClassModels () |
virtual void | loadModel (STDATA &stData) |
load model data from stData into SVM's. More... | |
virtual void | loadParameters (STDATA &stData) |
Read all parameters (e.g. More... | |
virtual void | loadParameters (StDataASCII &stData) |
virtual void | loadParameters (StDataCmdLine &stData) |
Same as loadParameters, but for Parameters from command line. More... | |
virtual int | nClasses () const |
get number of Classes (loadModel() or train() must have been called before) More... | |
size_t | nSupportVectors () const |
returns number of SV in model More... | |
void | optimizeLinearModel () |
optimize model for faster classification More... | |
virtual void | saveClassificationDetailsASCII (StDataASCII &stData) const |
classify the given Feature Vector. More... | |
virtual void | saveModel (STDATA &stData) const |
save resulting model from training process into given map More... | |
virtual void | saveOnlyKernelParameters (StDataASCII &stData) const |
save only Kernel Parameters (this is used for user information and to detect in grid search, wether a kernel parameter is changed More... | |
virtual void | saveParameters (STDATA &stData) const |
store all parameters of the SVM to given map More... | |
virtual void | saveParameters (StDataASCII &stData) const |
same as saveParameters(), but with fixed StDataASCII class independent from given STDATA template parameter. More... | |
virtual void | saveTrainingInfos (STDATA &stData, int detailLevel=1) |
save additional trainnig infos to given structured data More... | |
virtual void | saveTrainingInfos (StDataASCII &stData, int detailLevel=1) |
same as saveTrainingInfos(), but with fixed StDataASCII class independent from given STDATA template parameter. More... | |
virtual void | setProgressReporter (ProgressReporter *pr) |
set progress reporter object. More... | |
void | setStoreClassificationDetailsFlag (bool f) |
virtual void | train (const GroupedTrainingData< FV > &trainData) |
train SVM with given training data. More... | |
virtual void | train (const SVM_Problem< FV > &problem) |
train SVM with given Feature Vectors. More... | |
template<typename ForwardIter > | |
void | train (ForwardIter FV_begin, const ForwardIter &FV_end) |
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, Accessor accessor) |
same as train(), but you can specify an Accessor for accessing the elements of your container. More... | |
virtual void | updateKernelCache (const GroupedTrainingData< FV > &trainData) |
call updateCache() of selected kernel, e.g., for Kernel_MATRIX this will setup the internal cache matrix. More... | |
virtual void | updateKernelCache (const SVM_Problem< FV > &problem) |
same as previous updateKernelCache() method, just for feature vectors that are stored within an SVM_Problem object Before calling, please ensure that your feature vectors have correct uniqueId()'s More... | |
virtual void | updateTestKernelCache (typename std::vector< FV >::iterator FV_begin, const typename std::vector< FV >::iterator &FV_end) |
Load Test Kernel Cache. More... | |
Protected Member Functions | |
template<typename STDATA2 > | |
void | saveTrainingInfosTempl (STDATA2 &stData, int detailLevel) |
Protected Attributes | |
bool | _storeClassificationDetailsFlag |
Definition at line 109 of file BasicSVMAdapterTempl.hh.
|
inline |
Definition at line 112 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
set progress reporter object.
0 means no progress reporting. You are still the owner of this object, so you are responsible, that it exists during further calls to train(), etc. and that it is deleted afterwards
pr | pointer to ProgressReporter object or 0 if no progress reposting is desired |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 116 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
Read all parameters (e.g.
cost, gamma, etc) for the SVM from given structured data (e.g. an StDataASCII object). For non-existing keys the parameters remain unchanged, e.g. if key "cost" does not exist in the given map, the cost of the TwoClassSVMc will not be changed
stData | structured data containing parameters as key/value pairs |
. | depending on your STDATA class |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 124 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 130 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
Same as loadParameters, but for Parameters from command line.
The StDataCmdLine keeps track of unused parameters
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 136 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
load model data from stData into SVM's.
See documentation of this method in inherited classes for details.
stData | structured data containing parameters as key/value pairs |
. | depending on your STDATA class |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 143 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
store all parameters of the SVM to given map
stData | (output) structured data containing parameters as key/value pairs |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 149 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
same as saveParameters(), but with fixed StDataASCII class independent from given STDATA template parameter.
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 154 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
save only Kernel Parameters (this is used for user information and to detect in grid search, wether a kernel parameter is changed
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 159 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
save resulting model from training process into given map
stData | (output) structured data containing parameters as key/value pairs |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 166 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
save additional trainnig infos to given structured data
stData | (output) structured data containing parameters as key/value pairs |
detailLevel | 0: nothing, 1: only statistics, 2: training infos from all two-class trainings. Default 1 |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 171 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
same as saveTrainingInfos(), but with fixed StDataASCII class independent from given STDATA template parameter.
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 177 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
call updateCache() of selected kernel, e.g., for Kernel_MATRIX this will setup the internal cache matrix.
For pure Kernel_LINEAR or similar, this is an empty operation, so you can call it for every Kernel without negative effects. Before calling, please ensure that your feature vectors have correct uniqueId()'s
trainData | Structure with pointers to feature-vectors |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 183 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
same as previous updateKernelCache() method, just for feature vectors that are stored within an SVM_Problem object Before calling, please ensure that your feature vectors have correct uniqueId()'s
problem | Structure with pointers to feature-vectors |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 191 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
FV_begin | begin of test-feature-vectors. |
FV_end | end of test-feature-vectors. |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 199 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
train SVM with given training data.
(multi class interface) this is the basic method, all others will call this one. The The resulting model is stored internally and can be accessd via saveModel(), or used for classify()
trainData | Structure with pointers to feature-vectors sorted by classes, the class start indizes and a classIndexToLabel translastion table |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 215 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
train SVM with given Feature Vectors.
(general SVM interface – may also be used for one-class problems in future)
problem | Structure with pointers to feature-vectors and y's |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 223 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
call clearCache() method of selected kernel, e.g., for Kernel_MATRIX this will clear the internal cache matrix.
You should call this method if you used updateCache() before training and now want to use the SVM for the classification of vectors, that are not within the training data.
ATTENTION: If you don't clear the Cache before classification with a kernel like Kernel_MATRIX or Kernel_SCALE, only the uniqueID() of the feature vectors will be used
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 229 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
classify the given Feature Vector.
testObject | test object. |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 235 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
classify the given Feature Vector.
testObject | test object. | |
[out] | detailedResultsVec | vector with detailed results (results of all two class classifications) |
save classification details. Here the ordered labeles as "labels" and the according decision values as "dec_values". For this to work you must have called setStoreClassificationDetailsFlag( true) before classify()
resultVector | results from the classification |
stData | structured data, where to store the details |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 260 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
Evaluate kernel matrix of the svm.
A square matrix is generated with the current 2-class-svm-kernel. Assumption: memory is already allocated for kmatrix.
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 266 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
get number of Classes (loadModel() or train() must have been called before)
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 284 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
map classIndex to label (loadModel() or train() must have been called before)
classIndex | the index of the class (when sorted by labels) |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 289 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
returns number of SV in model
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 294 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
returns ith SV in model
i | the index of the SV |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 300 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
returns vector containing pointers to all TwoClassModels
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 305 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 315 of file BasicSVMAdapterTempl.hh.
|
inlinevirtual |
optimize model for faster classification
Implements svt::BasicSVMAdapter< FV, STDATA >.
Definition at line 325 of file BasicSVMAdapterTempl.hh.
|
inlineprotected |
Definition at line 337 of file BasicSVMAdapterTempl.hh.
Referenced by svt::BasicSVMAdapterTempl< FV, STDATA, MCSVMTYPE >::saveTrainingInfos().
|
inlineinherited |
train the Multi Class SVM with the given feature vectors.
The FeatureVector-Container must contain the Feature vectors directly, e.g., std::vector<MyFeatureVec>.
FV_begin | iterator to the first element of your FeatureVector-Container |
FV_end | iterator to one past the last element of your FeatureVector-Container |
Definition at line 344 of file BasicSVMAdapter.hh.
|
inlineinherited |
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*>
FVP_begin | iterator to the first element of your PointerToFeatureVector-Container |
FVP_end | iterator to one past the last element of your PointerToFeatureVector-Container |
accessor | functor, which accesses the feature vector in the container |
Definition at line 367 of file BasicSVMAdapter.hh.
|
inlineinherited |
Definition at line 393 of file BasicSVMAdapter.hh.
|
inlineinherited |
Definition at line 398 of file BasicSVMAdapter.hh.
|
protectedinherited |
Definition at line 517 of file BasicSVMAdapter.hh.
Referenced by svt::BasicSVMAdapter< FV, STDATA >::getStoreClassificationDetailsFlag(), and svt::BasicSVMAdapter< FV, STDATA >::setStoreClassificationDetailsFlag().