iRoCS Toolbox  1.1.0
Public Member Functions | Static Public Member Functions
svt::Kernel_SCALE< KERNEL > Class Template Reference

The Kernel_SCALE class provides a wrapper for other kernel classes , that scales the feature vectors, before they are passed to the wrapped kernel. More...

#include <Kernel_SCALE.hh>

Collaboration diagram for svt::Kernel_SCALE< KERNEL >:

Public Member Functions

 Kernel_SCALE ()
 
 Kernel_SCALE (const KERNEL &kernel)
 
const std::string & algorithm () const
 return selected algorithm (default is "") More...
 
template<typename ForwardIter , typename Accessor >
void calcScaleAndOffset (const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor) const
 calc scale factor and offset. More...
 
void clearCache () const
 
template<typename FV >
double k_function (const FV &x, const FV &y) const
 kernel function. More...
 
template<typename STDATA >
void loadParameters (STDATA &stData)
 
unsigned int nComponents () const
 number of components (features) in scale factor and offset More...
 
double offset (unsigned int index) const
 return offset for the nth component of the feature vector More...
 
template<typename STDATA >
void saveParameters (STDATA &stData) const
 save scale_factor and scale_offset. More...
 
double scaleFactor (unsigned int index) const
 return scale factor for the nth component of the feature vector More...
 
template<typename FV_IN , typename FV_OUT >
void scaleSingleFV (const FV_IN &fvIn, FV_OUT &fvOut) const
 scale single feature vector with internal offset and scale factor. More...
 
void setAlgorithm (const std::string &algorithm)
 set algorithm for data scaling More...
 
template<typename ForwardIter , typename Accessor >
void updateCache (const ForwardIter &fvBegin, const ForwardIter &fvEnd, Accessor accessor, ProgressReporter *pr=0) const
 update internal cache with scaled feature vectors, and (if algorithm is not empty) updates offsets and scaleFactors according to dataset and requested algorithm (e.g. More...
 
template<typename ForwardIter1 , typename Accessor1 , typename ForwardIter2 , typename Accessor2 >
void updateCache (const ForwardIter1 &, const ForwardIter1 &, Accessor1, const ForwardIter2 &, const ForwardIter2 &, Accessor2, ProgressReporter *=NULL) const
 

Static Public Member Functions

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

Detailed Description

template<typename KERNEL>
class svt::Kernel_SCALE< KERNEL >

The Kernel_SCALE class provides a wrapper for other kernel classes , that scales the feature vectors, before they are passed to the wrapped kernel.

For calculation the scale factors, a minmax and a stddev algorithm is available. The scaled feature vectors are cached (using their uniqueID()), so there is no performance drawback. The scale factors and offsets are saved like any other kernel parameters. So, when using this kernel for classification the given raw test data is scaled one-the-fly in the same way as the training data was scaled.

Parameters
KERNELkernel class that should be wrapped (see Kernel Classes for available kernels). KERNEL must fullfil the following interfaces

Definition at line 132 of file Kernel_SCALE.hh.

Constructor & Destructor Documentation

◆ Kernel_SCALE() [1/2]

template<typename KERNEL >
svt::Kernel_SCALE< KERNEL >::Kernel_SCALE ( )
inline

Definition at line 138 of file Kernel_SCALE.hh.

◆ Kernel_SCALE() [2/2]

template<typename KERNEL >
svt::Kernel_SCALE< KERNEL >::Kernel_SCALE ( const KERNEL &  kernel)
inline

Definition at line 143 of file Kernel_SCALE.hh.

Member Function Documentation

◆ setAlgorithm()

template<typename KERNEL >
void svt::Kernel_SCALE< KERNEL >::setAlgorithm ( const std::string &  algorithm)
inline

set algorithm for data scaling

Parameters
algorithmalgortihm as string

Definition at line 156 of file Kernel_SCALE.hh.

◆ algorithm()

template<typename KERNEL >
const std::string& svt::Kernel_SCALE< KERNEL >::algorithm ( ) const
inline

return selected algorithm (default is "")

Returns
selected algorithm (default is "")

Definition at line 168 of file Kernel_SCALE.hh.

◆ calcScaleAndOffset()

template<typename KERNEL >
template<typename ForwardIter , typename Accessor >
void svt::Kernel_SCALE< KERNEL >::calcScaleAndOffset ( const ForwardIter &  fvBegin,
const ForwardIter &  fvEnd,
Accessor  accessor 
) const

calc scale factor and offset.

ATTENTION: ensure that all feature Vectors return the same size() – even for SparseFV.

Parameters
fvBeginiterator to begin of feature vector list
fvEnditerator to end of feature vector list
accessoraccessor for Feature vector. Use svt::DirectAccessor (default) if your feature vectors are stored directly in the container, e.g. std::vector<FV>. Otherwise use svt::DereferencingAccessor, if your container has only pointers to the feature vectors, e.g. std::vector<FV*>

◆ scaleSingleFV()

template<typename KERNEL >
template<typename FV_IN , typename FV_OUT >
void svt::Kernel_SCALE< KERNEL >::scaleSingleFV ( const FV_IN &  fvIn,
FV_OUT &  fvOut 
) const
inline

scale single feature vector with internal offset and scale factor.

fvIn and fvOut must already have same sizes and must both implement size() and operator[]

Parameters
fvIninput feature vector
fvOut(output) scaled feature Vector. fvOut must already have the same size as fvIn

Definition at line 209 of file Kernel_SCALE.hh.

◆ updateCache() [1/2]

template<typename KERNEL >
template<typename ForwardIter , typename Accessor >
void svt::Kernel_SCALE< KERNEL >::updateCache ( const ForwardIter &  fvBegin,
const ForwardIter &  fvEnd,
Accessor  accessor,
ProgressReporter pr = 0 
) const

update internal cache with scaled feature vectors, and (if algorithm is not empty) updates offsets and scaleFactors according to dataset and requested algorithm (e.g.

"minmax"). This means: for training data, specify an algorithm, and for test data setAlgorithm() to empty string, so that offset and scaleFactors from training data are reused.

Parameters
fvBeginiterator to begin of feature vector container
fvEnditerator to end of feature vector container
accessoraccessor to acces Feature vector in container (e.g., svt::DirectAccessor of svt::DereferencingAccessor)
Exceptions
ScaleComponentsMismatchnumber of scale factors and number of feature vectors components don't match

◆ updateCache() [2/2]

template<typename KERNEL >
template<typename ForwardIter1 , typename Accessor1 , typename ForwardIter2 , typename Accessor2 >
void svt::Kernel_SCALE< KERNEL >::updateCache ( const ForwardIter1 &  ,
const ForwardIter1 &  ,
Accessor1  ,
const ForwardIter2 &  ,
const ForwardIter2 &  ,
Accessor2  ,
ProgressReporter = NULL 
) const
inline

Definition at line 249 of file Kernel_SCALE.hh.

◆ clearCache()

template<typename KERNEL >
void svt::Kernel_SCALE< KERNEL >::clearCache ( ) const
inline

Definition at line 260 of file Kernel_SCALE.hh.

◆ k_function()

template<typename KERNEL >
template<typename FV >
double svt::Kernel_SCALE< KERNEL >::k_function ( const FV &  x,
const FV &  y 
) const
inline

kernel function.

Passes scaled feature vectors to underlying Kernel function (that was specified as KERNEL template parameter). If updateCache() has been called before, the scaled feature vectors are taken from the cache, otherwise they will be calculated on the fly

Parameters
xfirst feature vector
ysecond feature vector
Returns
result from underlying Kernel function with scaled feature vectors

Definition at line 289 of file Kernel_SCALE.hh.

◆ nComponents()

template<typename KERNEL >
unsigned int svt::Kernel_SCALE< KERNEL >::nComponents ( ) const
inline

number of components (features) in scale factor and offset

Returns
number of components (features) in scale factor and offset

Definition at line 335 of file Kernel_SCALE.hh.

◆ scaleFactor()

template<typename KERNEL >
double svt::Kernel_SCALE< KERNEL >::scaleFactor ( unsigned int  index) const
inline

return scale factor for the nth component of the feature vector

Returns
scale factor for the nth component of the feature vector

Definition at line 349 of file Kernel_SCALE.hh.

◆ offset()

template<typename KERNEL >
double svt::Kernel_SCALE< KERNEL >::offset ( unsigned int  index) const
inline

return offset for the nth component of the feature vector

Returns
offset for the nth component of the feature vector

Definition at line 362 of file Kernel_SCALE.hh.

◆ loadParameters()

template<typename KERNEL >
template<typename STDATA >
void svt::Kernel_SCALE< KERNEL >::loadParameters ( STDATA &  stData)
inline

Definition at line 368 of file Kernel_SCALE.hh.

◆ saveParameters()

template<typename KERNEL >
template<typename STDATA >
void svt::Kernel_SCALE< KERNEL >::saveParameters ( STDATA &  stData) const
inline

save scale_factor and scale_offset.

ATTENTION: the algorithm is saved to 'scale_used_algorithm', which is another key as in loadParameters (there it expects the algorithm in 'scale_algorithm'). This ensures, that when parameters are loaded from a model, the _algorithm keeps empty and therefore the scale_offset and scale_factor from training data set are reused as it should be.

Parameters
stDatastructured data, where to save the parameters

Definition at line 408 of file Kernel_SCALE.hh.

◆ name()

template<typename KERNEL >
static std::string svt::Kernel_SCALE< KERNEL >::name ( )
inlinestatic

Definition at line 427 of file Kernel_SCALE.hh.

◆ description()

template<typename KERNEL >
static std::string svt::Kernel_SCALE< KERNEL >::description ( )
inlinestatic

Definition at line 432 of file Kernel_SCALE.hh.

◆ getParamInfos()

template<typename KERNEL >
static void svt::Kernel_SCALE< KERNEL >::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 447 of file Kernel_SCALE.hh.


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