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>
|
| 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 |
|
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
-
KERNEL | kernel 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.
◆ Kernel_SCALE() [1/2]
template<typename KERNEL >
◆ Kernel_SCALE() [2/2]
template<typename KERNEL >
◆ setAlgorithm()
template<typename KERNEL >
set algorithm for data scaling
- Parameters
-
algorithm | algortihm as string |
Definition at line 156 of file Kernel_SCALE.hh.
◆ algorithm()
template<typename KERNEL >
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
-
fvBegin | iterator to begin of feature vector list |
fvEnd | iterator to end of feature vector list |
accessor | accessor 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
-
fvIn | input 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 >
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
-
- Exceptions
-
◆ 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 |
◆ clearCache()
template<typename KERNEL >
◆ k_function()
template<typename KERNEL >
template<typename FV >
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
-
x | first feature vector |
y | second 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 >
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 >
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 >
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 >
◆ saveParameters()
template<typename KERNEL >
template<typename STDATA >
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
-
stData | structured data, where to save the parameters |
Definition at line 408 of file Kernel_SCALE.hh.
◆ name()
template<typename KERNEL >
◆ description()
template<typename KERNEL >
◆ getParamInfos()
template<typename KERNEL >
get information about the parameters, that are used in loadParameters() and saveParameters().
The Infos are appended to the passed array
- Parameters
-
p | array 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: