shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer > Class Template Reference

Super class of all kernelized (non-linear) SVM trainers. More...

#include <shark/Algorithms/Trainers/AbstractSvmTrainer.h>

+ Inheritance diagram for shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >:

Public Types

typedef AbstractKernelFunction< InputTypeKernelType
 
- Public Types inherited from shark::IParameterizable<>
typedef RealVector ParameterVectorType
 

Public Member Functions

 AbstractSvmTrainer (KernelType *kernel, double C, bool offset, bool unconstrained=false)
 
 AbstractSvmTrainer (KernelType *kernel, double negativeC, double positiveC, bool offset, bool unconstrained=false)
 
double C () const
 Return the value of the regularization parameter C. More...
 
void setC (double C)
 Set the value of the regularization parameter C. More...
 
RealVector const & regularizationParameters () const
 
void setRegularizationParameters (RealVector const &regularizers)
 Set the value of the regularization parameter C. More...
 
KernelTypekernel ()
 
KernelType const * kernel () const
 
void setKernel (KernelType *kernel)
 
bool isUnconstrained () const
 
bool trainOffset () const
 
std::size_t cacheSize () const
 
void setCacheSize (std::size_t size)
 
RealVector parameterVector () const
 get the hyper-parameter vector More...
 
void setParameterVector (RealVector const &newParameters)
 set the vector of hyper-parameters More...
 
size_t numberOfParameters () const
 return the number of hyper-parameters More...
 
- Public Member Functions inherited from shark::QpConfig
 QpConfig (bool precomputedFlag=false, bool sparsifyFlag=true)
 Constructor. More...
 
QpStoppingConditionstoppingCondition ()
 Read/write access to the stopping condition. More...
 
QpStoppingCondition const & stoppingCondition () const
 Read access to the stopping condition. More...
 
QpSolutionPropertiessolutionProperties ()
 Access to the solution properties. More...
 
bool & precomputeKernel ()
 Flag for using a precomputed kernel matrix. More...
 
bool const & precomputeKernel () const
 Flag for using a precomputed kernel matrix. More...
 
bool & sparsify ()
 Flag for sparsifying the model after training. More...
 
bool const & sparsify () const
 Flag for sparsifying the model after training. More...
 
bool & shrinking ()
 Flag for shrinking in the decomposition solver. More...
 
bool const & shrinking () const
 Flag for shrinking in the decomposition solver. More...
 
bool & s2do ()
 Flag for S2DO (instead of SMO) More...
 
bool const & s2do () const
 Flag for S2DO (instead of SMO) More...
 
unsigned int & verbosity ()
 Verbosity level of the solver. More...
 
unsigned int const & verbosity () const
 Verbosity level of the solver. More...
 
unsigned long long const & accessCount () const
 Number of kernel accesses. More...
 
void setMinAccuracy (double a)
 
void setMaxIterations (unsigned long long i)
 
void setTargetValue (double v)
 
void setMaxSeconds (double s)
 
- Public Member Functions inherited from shark::IParameterizable<>
virtual ~IParameterizable ()
 

Protected Attributes

KernelTypem_kernel
 
RealVector m_regularizers
 Vector of regularization parameters. More...
 
bool m_trainOffset
 
bool m_unconstrained
 Is log(C) stored internally as a parameter instead of C? If yes, then we get rid of the constraint C > 0 on the level of the parameter interface. More...
 
std::size_t m_cacheSize
 Number of values in the kernel cache. The size of the cache in bytes is the size of one entry (4 for float, 8 for double) times this number. More...
 
- Protected Attributes inherited from shark::QpConfig
QpStoppingCondition m_stoppingcondition
 conditions for when to stop the QP solver More...
 
QpSolutionProperties m_solutionproperties
 properties of the approximate solution found by the solver More...
 
bool m_precomputedKernelMatrix
 should the solver use a precomputed kernel matrix? More...
 
bool m_sparsify
 should the trainer sparsify the model after training? More...
 
bool m_shrinking
 should shrinking be used? More...
 
bool m_s2do
 should S2DO be used instead of SMO? More...
 
unsigned int m_verbosity
 verbosity level (currently unused) More...
 
unsigned long long m_accessCount
 kernel access count More...
 

Detailed Description

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
class shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >

Super class of all kernelized (non-linear) SVM trainers.

This class holds general information shared by most if not all SVM trainers. First of all, this includes the kernel and the regularization parameter. The class also manages meta-information of the training process, like the maximal size of the kernel cache, the stopping criterion, as well as information on the actual solution.

Definition at line 185 of file AbstractSvmTrainer.h.

Member Typedef Documentation

◆ KernelType

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
typedef AbstractKernelFunction<InputType> shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::KernelType

Definition at line 189 of file AbstractSvmTrainer.h.

Constructor & Destructor Documentation

◆ AbstractSvmTrainer() [1/2]

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::AbstractSvmTrainer ( KernelType kernel,
double  C,
bool  offset,
bool  unconstrained = false 
)
inline

Constructor

Parameters
kernelkernel function to use for training and prediction
Cregularization parameter - always the 'true' value of C, even when unconstrained is set
offsettrain svm with offset - this is not supported for all SVM solvers.
unconstrainedwhen a C-value is given via setParameter, should it be piped through the exp-function before using it in the solver?

Definition at line 196 of file AbstractSvmTrainer.h.

◆ AbstractSvmTrainer() [2/2]

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::AbstractSvmTrainer ( KernelType kernel,
double  negativeC,
double  positiveC,
bool  offset,
bool  unconstrained = false 
)
inline

Constructor featuring two regularization parameters

Parameters
kernelkernel function to use for training and prediction
negativeCregularization parameter of the negative class (label 0)
positiveCregularization parameter of the positive class (label 1)
offsettrain svm with offset - this is not supported for all SVM solvers.
unconstrainedwhen a C-value is given via setParameter, should it be piped through the exp-function before using it in the solver?

Definition at line 213 of file AbstractSvmTrainer.h.

Member Function Documentation

◆ C()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
double shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::C ( ) const
inline

Return the value of the regularization parameter C.

Definition at line 229 of file AbstractSvmTrainer.h.

◆ cacheSize()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
std::size_t shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::cacheSize ( ) const
inline

Definition at line 266 of file AbstractSvmTrainer.h.

◆ isUnconstrained()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
bool shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::isUnconstrained ( ) const
inline

Definition at line 260 of file AbstractSvmTrainer.h.

◆ kernel() [1/2]

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
KernelType* shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::kernel ( )
inline

◆ kernel() [2/2]

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
KernelType const* shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::kernel ( ) const
inline

Definition at line 253 of file AbstractSvmTrainer.h.

◆ numberOfParameters()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
size_t shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::numberOfParameters ( ) const
inlinevirtual

return the number of hyper-parameters

Reimplemented from shark::IParameterizable<>.

Definition at line 290 of file AbstractSvmTrainer.h.

◆ parameterVector()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
RealVector shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::parameterVector ( ) const
inlinevirtual

get the hyper-parameter vector

Reimplemented from shark::IParameterizable<>.

Definition at line 272 of file AbstractSvmTrainer.h.

◆ regularizationParameters()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
RealVector const& shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::regularizationParameters ( ) const
inline

Definition at line 240 of file AbstractSvmTrainer.h.

◆ setC()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
void shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setC ( double  C)
inline

Set the value of the regularization parameter C.

Definition at line 235 of file AbstractSvmTrainer.h.

◆ setCacheSize()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
void shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setCacheSize ( std::size_t  size)
inline

Definition at line 268 of file AbstractSvmTrainer.h.

◆ setKernel()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
void shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setKernel ( KernelType kernel)
inline

Definition at line 255 of file AbstractSvmTrainer.h.

◆ setParameterVector()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
void shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setParameterVector ( RealVector const &  newParameters)
inlinevirtual

set the vector of hyper-parameters

Reimplemented from shark::IParameterizable<>.

Definition at line 280 of file AbstractSvmTrainer.h.

◆ setRegularizationParameters()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
void shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setRegularizationParameters ( RealVector const &  regularizers)
inline

Set the value of the regularization parameter C.

Definition at line 246 of file AbstractSvmTrainer.h.

◆ trainOffset()

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
bool shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::trainOffset ( ) const
inline

Definition at line 263 of file AbstractSvmTrainer.h.

Member Data Documentation

◆ m_cacheSize

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
std::size_t shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_cacheSize
protected

Number of values in the kernel cache. The size of the cache in bytes is the size of one entry (4 for float, 8 for double) times this number.

Definition at line 305 of file AbstractSvmTrainer.h.

◆ m_kernel

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
KernelType* shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_kernel
protected

Kernel object.

Definition at line 295 of file AbstractSvmTrainer.h.

◆ m_regularizers

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
RealVector shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_regularizers
protected

Vector of regularization parameters.

If the size of the vector is 1 there is only one regularization parameter for all classes, else there must be one for every class in the dataset. The exact meaning depends on the sub-class, but the value is always positive, and higher implies a less regular solution.

Definition at line 302 of file AbstractSvmTrainer.h.

◆ m_trainOffset

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
bool shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_trainOffset
protected

Definition at line 303 of file AbstractSvmTrainer.h.

◆ m_unconstrained

template<class InputType, class LabelType, class Model = KernelClassifier<InputType>, class Trainer = AbstractTrainer< Model,LabelType>>
bool shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_unconstrained
protected

Is log(C) stored internally as a parameter instead of C? If yes, then we get rid of the constraint C > 0 on the level of the parameter interface.

Definition at line 304 of file AbstractSvmTrainer.h.


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