iRoCS Toolbox  1.1.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
svt::TwoClassSVMnu< KF > Class Template Reference

The TwoClassSVMnu class (is/provides/specifies/contains) More...

#include <TwoClassSVMnu.hh>

Inheritance diagram for svt::TwoClassSVMnu< KF >:
Collaboration diagram for svt::TwoClassSVMnu< KF >:

Public Types

typedef KF KF_type
 

Public Member Functions

 TwoClassSVMnu ()
 (description) More...
 
 TwoClassSVMnu (const KF &kernel)
 (description) More...
 
 ~TwoClassSVMnu ()
 (description) More...
 
float cacheSizeMB () const
 
template<typename FV , typename ForwardIter >
void calcClassificationCache (const FV &testObject, const ForwardIter &SVP_begin, const ForwardIter &SVP_end, std::vector< double > &kernelResultByUID) const
 caculcate the Classification Cache kernelResultByUID, which contains kernel evaluations for classification. More...
 
template<typename FV , typename ForwardIter , typename FVGradient >
void calcGradientCache (const FV &testObject, const ForwardIter &SVP_begin, const ForwardIter &SVP_end, std::vector< FVGradient > &gradientOfKernelResultByUID) const
 compute the gradient of the kernel Result for given testObject and support vectors. More...
 
template<typename FV >
double classify (const FV &testObject, const Model< FV > &model) const
 standard classification without caching the kernel evaluations. More...
 
template<typename FV >
double classifyWithCache (const Model< FV > &model, const std::vector< double > &kernelResultByUID) const
 classify testObject (that was passed to calcClassificationCache() before) using the given model.The kernel evaluations (kernelResulsByUID) must be computed before by calcClassificationCache. More...
 
void clearKernelCache () const
 call the clearCache() method of selected Kernel More...
 
template<typename FV , typename FVGradient >
void gradientOfDecisionFunction (const Model< FV > &model, const std::vector< FVGradient > &gradientOfKernelResultByUID, FVGradient &gradient) const
 compute the gradient of the decision function at testObject's position in the feature space for the given model. More...
 
KF & kernel ()
 access the kernel function More...
 
const KF & kernel () const
 
template<typename STDATA >
void loadParameters (STDATA &stData)
 Load and save parameter nu from map. More...
 
double nu () const
 
template<typename STDATA >
void saveParameters (STDATA &stData) const
 
void setCacheSizeMB (float s)
 set cache memory size in MB (default: 40) More...
 
void setNu (double nu)
 set the parameter nu of nu-SVC. More...
 
void setProgressReporter (ProgressReporter *pr)
 set a progress reporter object. More...
 
void setShrinkingFlag (bool f)
 whether to use the shrinking heuristics (default: true) More...
 
void setTerminationEpsilon (double e)
 set tolerance of termination criterion (default: 0.001) More...
 
bool shrinkingFlag () const
 
double terminationEpsilon () const
 
template<typename FV >
void train (const SVM_Problem< FV > &problem, Model< FV > &model) const
 train SVM with given Feature Vectors. More...
 
template<typename ForwardIter >
void train (ForwardIter FV_begin, const ForwardIter &FV_end, svt::Model< typename std::iterator_traits< ForwardIter >::value_type > &model) const
 train (STL-like interface) Your feature vector class must provide a method double getLabel(), which returns +1 or -1. More...
 
template<typename ForwardIter , typename Accessor >
void train (ForwardIter FV_begin, const ForwardIter &FV_end, svt::Model< typename Accessor::template Traits< ForwardIter >::value_type > &model, Accessor accessor) const
 train (STL-like interface with additional Accessor) More...
 
template<typename ForwardIter , typename Accessor >
void updateKernelCache (const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor) const
 call the updateCache() method of selected Kernel More...
 

Static Public Member Functions

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

Protected Member Functions

template<typename FV >
void solve_nu_svc (const SVM_Problem< FV > *prob, double *alpha, SolutionInfo *si, Model< FV > &model) const
 

Protected Attributes

float _cacheSizeMB
 
ProgressReporter_pr
 
bool _shrinkingFlag
 
double _terminationEpsilon
 
KF p_kernel
 

Detailed Description

template<typename KF>
class svt::TwoClassSVMnu< KF >

The TwoClassSVMnu class (is/provides/specifies/contains)

(description)

Definition at line 126 of file TwoClassSVMnu.hh.

Member Typedef Documentation

◆ KF_type

template<typename KF >
typedef KF svt::TwoClassSVM< KF >::KF_type
inherited

Definition at line 137 of file TwoClassSVM.hh.

Constructor & Destructor Documentation

◆ TwoClassSVMnu() [1/2]

template<typename KF >
svt::TwoClassSVMnu< KF >::TwoClassSVMnu ( )

(description)

◆ TwoClassSVMnu() [2/2]

template<typename KF >
svt::TwoClassSVMnu< KF >::TwoClassSVMnu ( const KF &  kernel)

(description)

Parameters

◆ ~TwoClassSVMnu()

template<typename KF >
svt::TwoClassSVMnu< KF >::~TwoClassSVMnu ( )

(description)

Member Function Documentation

◆ train() [1/3]

template<typename KF >
template<typename FV >
void svt::TwoClassSVMnu< KF >::train ( const SVM_Problem< FV > &  problem,
Model< FV > &  model 
) const

train SVM with given Feature Vectors.

(raw interface)

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

Parameters
probStructure with pointers to feature-vectors
model(output) model containing pointers to feature vectors, that became support vectors, alphas and rho

Referenced by svt::TwoClassSVMnu< KF >::train().

◆ train() [2/3]

template<typename KF >
template<typename ForwardIter >
void svt::TwoClassSVMnu< KF >::train ( ForwardIter  FV_begin,
const ForwardIter &  FV_end,
svt::Model< typename std::iterator_traits< ForwardIter >::value_type > &  model 
) const
inline

train (STL-like interface) Your feature vector class must provide a method double getLabel(), which returns +1 or -1.

The ModelType is svt::Model<FV>. Positive and negative labled feature vectors may be in any order in the given Container.

Parameters
FV_beginiterator pointing to first element of the container with the feature vectors
FV_enditerator pointing one past the last element of the container with the feature vectors
model(output) model containing pointers to feature vectors, that became support vectors, alphas and rho

Definition at line 192 of file TwoClassSVMnu.hh.

◆ train() [3/3]

template<typename KF >
template<typename ForwardIter , typename Accessor >
void svt::TwoClassSVMnu< KF >::train ( ForwardIter  FV_begin,
const ForwardIter &  FV_end,
svt::Model< typename Accessor::template Traits< ForwardIter >::value_type > &  model,
Accessor  accessor 
) const

train (STL-like interface with additional Accessor)

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
FV_beginiterator pointing to first element of the container with the feature vectors
FV_enditerator pointing one past the last element of the container with the feature vectors
model(output) model containing pointers to feature vectors, that became support vectors, alphas and rho
accessorfunctor, which accesses the feature vector in the container

◆ setNu()

template<typename KF >
void svt::TwoClassSVMnu< KF >::setNu ( double  nu)
inline

set the parameter nu of nu-SVC.

Default: 0.5

Parameters
nunew value for nu

Definition at line 235 of file TwoClassSVMnu.hh.

◆ nu()

template<typename KF >
double svt::TwoClassSVMnu< KF >::nu ( ) const
inline

Definition at line 240 of file TwoClassSVMnu.hh.

Referenced by svt::TwoClassSVMnu< KF >::setNu().

◆ loadParameters()

template<typename KF >
template<typename STDATA >
void svt::TwoClassSVMnu< KF >::loadParameters ( STDATA &  stData)
inline

Load and save parameter nu from map.

Definition at line 252 of file TwoClassSVMnu.hh.

◆ saveParameters()

template<typename KF >
template<typename STDATA >
void svt::TwoClassSVMnu< KF >::saveParameters ( STDATA &  stData) const
inline

Definition at line 261 of file TwoClassSVMnu.hh.

◆ name()

template<typename KF >
static const char* svt::TwoClassSVMnu< KF >::name ( )
inlinestatic

Definition at line 270 of file TwoClassSVMnu.hh.

Referenced by svt::TwoClassSVMnu< KF >::saveParameters().

◆ description()

template<typename KF >
static const char* svt::TwoClassSVMnu< KF >::description ( )
inlinestatic

Definition at line 275 of file TwoClassSVMnu.hh.

◆ getParamInfos()

template<typename KF >
static void svt::TwoClassSVMnu< KF >::getParamInfos ( std::vector< ParamInfo > &  p)
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 290 of file TwoClassSVMnu.hh.

◆ solve_nu_svc()

template<typename KF >
template<typename FV >
void svt::TwoClassSVMnu< KF >::solve_nu_svc ( const SVM_Problem< FV > *  prob,
double *  alpha,
SolutionInfo si,
Model< FV > &  model 
) const
protected

◆ calcClassificationCache()

template<typename KF >
template<typename FV , typename ForwardIter >
void svt::TwoClassSVM< KF >::calcClassificationCache ( const FV &  testObject,
const ForwardIter &  SVP_begin,
const ForwardIter &  SVP_end,
std::vector< double > &  kernelResultByUID 
) const
inherited

caculcate the Classification Cache kernelResultByUID, which contains kernel evaluations for classification.

This is separated from the classify method, because multiclass-algorithms often need the evaluated kernels multiple times. To identify the requested support vectors in classifyWithCache() each given support vector must provide a uniqueID() method, that returns a unique index (unsigend int) between 0 and kernelResultByUID.size()

Parameters
testObjectfeature vector of the test object
SV_beginbegin of container with pointers to support vectors
SV_endend of container with pointers to support vectors
kernelResultByUID(output) vector with kernel evaluation results by uniqueID() of feature vector. Must have already the correct size!

Definition at line 93 of file TwoClassSVM.hh.

Referenced by svt::TwoClassSVM< KF >::~TwoClassSVM().

◆ classifyWithCache()

template<typename KF >
template<typename FV >
double svt::TwoClassSVM< KF >::classifyWithCache ( const Model< FV > &  model,
const std::vector< double > &  kernelResultByUID 
) const
inherited

classify testObject (that was passed to calcClassificationCache() before) using the given model.The kernel evaluations (kernelResulsByUID) must be computed before by calcClassificationCache.

Parameters
modelmodel containing Support Vectors, alphas and rho. Each Support Vector must provide a uniqueID() method, to find the cached kernel evalutaion, that was calculated in calcClassificationCache()
kernelResultByUIDvector with kernel evaluation results by uniqueID() of feature vector.
Returns
decision value

Definition at line 118 of file TwoClassSVM.hh.

Referenced by svt::TwoClassSVM< KF >::~TwoClassSVM().

◆ calcGradientCache()

template<typename KF >
template<typename FV , typename ForwardIter , typename FVGradient >
void svt::TwoClassSVM< KF >::calcGradientCache ( const FV &  testObject,
const ForwardIter &  SVP_begin,
const ForwardIter &  SVP_end,
std::vector< FVGradient > &  gradientOfKernelResultByUID 
) const
inherited

compute the gradient of the kernel Result for given testObject and support vectors.

Parameters
testObjectfeature vector of the test object
SVP_beginbegin of container with pointers to support vectors
SVP_endend of container with pointers to support vectors
[out]gradientOfKernelResultByUID(output) vector with gradient of kernel results for testObject and each given support vector. the std::vector container must have already the correct size and each FVGradient must already have the correctnumber of components.

Referenced by svt::TwoClassSVM< KF >::~TwoClassSVM().

◆ gradientOfDecisionFunction()

template<typename KF >
template<typename FV , typename FVGradient >
void svt::TwoClassSVM< KF >::gradientOfDecisionFunction ( const Model< FV > &  model,
const std::vector< FVGradient > &  gradientOfKernelResultByUID,
FVGradient &  gradient 
) const
inherited

compute the gradient of the decision function at testObject's position in the feature space for the given model.

The gradientOfKernelResultByUID must have been computed before by passing your testObject to calcGradientCache()

Parameters
modelmodel containing Support Vectors, alphas and rho. Each Support Vector must provide a uniqueID() method
gradientOfKernelResultByUIDkernel gradient evaluations for the testObject with each support vector, computed with calcGradientCache()
[out]gradientresulting gradient of the decision function. the passed vector must already have the correct number of components

Referenced by svt::TwoClassSVM< KF >::~TwoClassSVM().

◆ kernel() [1/2]

template<typename KF >
KF& svt::SVMBase< KF >::kernel ( )
inlineinherited

access the kernel function

Returns
reference to kernel function

Definition at line 164 of file SVMBase.hh.

◆ kernel() [2/2]

template<typename KF >
const KF& svt::SVMBase< KF >::kernel ( ) const
inlineinherited

Definition at line 170 of file SVMBase.hh.

◆ updateKernelCache()

template<typename KF >
template<typename ForwardIter , typename Accessor >
void svt::SVMBase< KF >::updateKernelCache ( const ForwardIter &  fvBegin,
const ForwardIter &  fvEnd,
Accessor  accessor 
) const
inlineinherited

call the updateCache() method of selected Kernel

Parameters

Definition at line 187 of file SVMBase.hh.

◆ clearKernelCache()

template<typename KF >
void svt::SVMBase< KF >::clearKernelCache ( ) const
inlineinherited

call the clearCache() method of selected Kernel

Parameters

Definition at line 206 of file SVMBase.hh.

◆ classify()

template<typename KF >
template<typename FV >
double svt::SVMBase< KF >::classify ( const FV &  testObject,
const Model< FV > &  model 
) const
inherited

standard classification without caching the kernel evaluations.

Parameters
testObjectfeature vector of the test object
modelmodel containing Support Vectors, alphas and rho.
Returns
decision value

Referenced by svt::SVMBase< KF >::clearKernelCache().

◆ setTerminationEpsilon()

template<typename KF >
void svt::SVMBase< KF >::setTerminationEpsilon ( double  e)
inlineinherited

set tolerance of termination criterion (default: 0.001)

Parameters
enew value for epsilon

Definition at line 236 of file SVMBase.hh.

◆ terminationEpsilon()

template<typename KF >
double svt::SVMBase< KF >::terminationEpsilon ( ) const
inlineinherited

Definition at line 241 of file SVMBase.hh.

Referenced by svt::SVMBase< KF >::saveParameters().

◆ setCacheSizeMB()

template<typename KF >
void svt::SVMBase< KF >::setCacheSizeMB ( float  s)
inlineinherited

set cache memory size in MB (default: 40)

Parameters
scache size in MBytes

Definition at line 255 of file SVMBase.hh.

◆ cacheSizeMB()

template<typename KF >
float svt::SVMBase< KF >::cacheSizeMB ( ) const
inlineinherited

Definition at line 260 of file SVMBase.hh.

Referenced by svt::SVMBase< KF >::saveParameters().

◆ setShrinkingFlag()

template<typename KF >
void svt::SVMBase< KF >::setShrinkingFlag ( bool  f)
inlineinherited

whether to use the shrinking heuristics (default: true)

Parameters
ftrue = use shrinking heuristics

Definition at line 274 of file SVMBase.hh.

◆ shrinkingFlag()

template<typename KF >
bool svt::SVMBase< KF >::shrinkingFlag ( ) const
inlineinherited

Definition at line 279 of file SVMBase.hh.

Referenced by svt::SVMBase< KF >::saveParameters().

◆ setProgressReporter()

template<typename KF >
void svt::SVMBase< KF >::setProgressReporter ( ProgressReporter pr)
inlineinherited

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 358 of file SVMBase.hh.

Field Documentation

◆ p_kernel

template<typename KF >
KF svt::SVMBase< KF >::p_kernel
protectedinherited

◆ _terminationEpsilon

template<typename KF >
double svt::SVMBase< KF >::_terminationEpsilon
protectedinherited

◆ _cacheSizeMB

template<typename KF >
float svt::SVMBase< KF >::_cacheSizeMB
protectedinherited

◆ _shrinkingFlag

template<typename KF >
bool svt::SVMBase< KF >::_shrinkingFlag
protectedinherited

◆ _pr

template<typename KF >
ProgressReporter* svt::SVMBase< KF >::_pr
protectedinherited

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