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::AbstractTrainer< Model, LabelTypeT >
typedef Model ModelType
 
typedef ModelType::InputType InputType
 
typedef LabelTypeT LabelType
 
typedef LabeledData< InputType, LabelTypeDatasetType
 
- Public Types inherited from shark::IParameterizable< VectorType >
typedef VectorType 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.
 
void setC (double C)
 Set the value of the regularization parameter C.
 
RealVector const & regularizationParameters () const
 
void setRegularizationParameters (RealVector const &regularizers)
 Set the value of the regularization parameter C.
 
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
 
void setParameterVector (RealVector const &newParameters)
 set the vector of hyper-parameters
 
size_t numberOfParameters () const
 return the number of hyper-parameters
 
- Public Member Functions inherited from shark::AbstractTrainer< Model, LabelTypeT >
virtual void train (ModelType &model, DatasetType const &dataset)=0
 Core of the Trainer interface.
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
virtual std::string name () const
 returns the name of the object
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor.
 
virtual void read (InArchive &archive)
 Read the component from the supplied archive.
 
virtual void write (OutArchive &archive) const
 Write the component to the supplied archive.
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...).
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...).
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 
- Public Member Functions inherited from shark::QpConfig
 QpConfig (bool precomputedFlag=false, bool sparsifyFlag=true)
 Constructor.
 
QpStoppingConditionstoppingCondition ()
 Read/write access to the stopping condition.
 
QpStoppingCondition const & stoppingCondition () const
 Read access to the stopping condition.
 
QpSolutionPropertiessolutionProperties ()
 Access to the solution properties.
 
bool & precomputeKernel ()
 Flag for using a precomputed kernel matrix.
 
bool const & precomputeKernel () const
 Flag for using a precomputed kernel matrix.
 
bool & sparsify ()
 Flag for sparsifying the model after training.
 
bool const & sparsify () const
 Flag for sparsifying the model after training.
 
bool & shrinking ()
 Flag for shrinking in the decomposition solver.
 
bool const & shrinking () const
 Flag for shrinking in the decomposition solver.
 
bool & s2do ()
 Flag for S2DO (instead of SMO)
 
bool const & s2do () const
 Flag for S2DO (instead of SMO)
 
unsigned int & verbosity ()
 Verbosity level of the solver.
 
unsigned int const & verbosity () const
 Verbosity level of the solver.
 
unsigned long long const & accessCount () const
 Number of kernel accesses.
 
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< VectorType >
virtual ~IParameterizable ()
 

Protected Attributes

KernelTypem_kernel
 
RealVector m_regularizers
 Vector of regularization parameters.
 
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.
 
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.
 
- Protected Attributes inherited from shark::QpConfig
QpStoppingCondition m_stoppingcondition
 conditions for when to stop the QP solver
 
QpSolutionProperties m_solutionproperties
 properties of the approximate solution found by the solver
 
bool m_precomputedKernelMatrix
 should the solver use a precomputed kernel matrix?
 
bool m_sparsify
 should the trainer sparsify the model after training?
 
bool m_shrinking
 should shrinking be used?
 
bool m_s2do
 should S2DO be used instead of SMO?
 
unsigned int m_verbosity
 verbosity level (currently unused)
 
unsigned long long m_accessCount
 kernel access count
 

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.

References shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::C(), shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::kernel(), and SHARK_RUNTIME_CHECK.

◆ 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.

References shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::kernel(), shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_regularizers, and SHARK_RUNTIME_CHECK.

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

◆ 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

◆ 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

◆ kernel() [1/2]

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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.

References shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::m_regularizers, and SHARK_RUNTIME_CHECK.

◆ 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

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.

Referenced by shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::cacheSize(), and shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setCacheSize().

◆ m_kernel

◆ 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

◆ 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

◆ 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.

Referenced by shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::isUnconstrained(), shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::parameterVector(), and shark::AbstractSvmTrainer< InputType, LabelType, Model, Trainer >::setParameterVector().


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