shark::RankingSvmTrainer< InputType, CacheType > Class Template Reference

Training of an SVM for ranking. More...

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

+ Inheritance diagram for shark::RankingSvmTrainer< InputType, CacheType >:

Public Types

typedef CacheType QpFloatType
 Convenience typedefs: this and many of the below typedefs build on the class template type CacheType. Simply changing that one template parameter CacheType thus allows to flexibly switch between using float or double as type for caching the kernel values. The default is float, offering sufficient accuracy in the vast majority of cases, at a memory cost of only four bytes. However, the template parameter makes it easy to use double instead, (e.g., in case high accuracy training is needed). More...
 
typedef AbstractKernelFunction< InputTypeKernelType
 
- Public Types inherited from shark::AbstractSvmTrainer< InputType, unsigned int, KernelExpansion< InputType > >
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<>
typedef RealVector ParameterVectorType
 

Public Member Functions

 RankingSvmTrainer (KernelType *kernel, double C, bool unconstrained=false)
 
std::string name () const
 From INameable: return the class name. More...
 
void train (KernelExpansion< InputType > &function, Data< InputType > const &dataset)
 Train the ranking SVM. More...
 
void train (KernelExpansion< InputType > &function, LabeledData< InputType, unsigned int > const &dataset)
 Train the ranking SVM. More...
 
void train (KernelExpansion< InputType > &function, Data< InputType > const &dataset, std::vector< std::pair< std::size_t, std::size_t >> const &pairs)
 Train the ranking SVM. More...
 
- Public Member Functions inherited from shark::AbstractSvmTrainer< InputType, unsigned int, KernelExpansion< InputType > >
 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::AbstractTrainer< Model, LabelTypeT >
virtual void train (ModelType &model, DatasetType const &dataset)=0
 Core of the Trainer interface. More...
 
- Public Member Functions inherited from shark::INameable
virtual ~INameable ()
 
- Public Member Functions inherited from shark::ISerializable
virtual ~ISerializable ()
 Virtual d'tor. More...
 
virtual void read (InArchive &archive)
 Read the component from the supplied archive. More...
 
virtual void write (OutArchive &archive) const
 Write the component to the supplied archive. More...
 
void load (InArchive &archive, unsigned int version)
 Versioned loading of components, calls read(...). More...
 
void save (OutArchive &archive, unsigned int version) const
 Versioned storing of components, calls write(...). More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 
- 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 ()
 

Additional Inherited Members

- Protected Attributes inherited from shark::AbstractSvmTrainer< InputType, unsigned int, KernelExpansion< InputType > >
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 CacheType = float>
class shark::RankingSvmTrainer< InputType, CacheType >

Training of an SVM for ranking.

A ranking SVM trains a function (linear or linear in a kernel induced feature space, RKHS) with the aim that the function values are consistent with given pairwise rankings. I.e., given are pairs (a, b) of points, and the task of SVM training is to find a function f such that f(a) < f(b). More exactly, the hard margin ranking SVM aims for f(b) - f(a) >= 1 while minimizing the squared RKHS norm of f. The soft-margin SVM relates the constraint analogous to a standard C-SVM.

The trained model is a real-valued function. To predict the ranking of a pair of points the function is applied to both points. The one with smaller function value is ranked as being "smaller", i.e., if f is the trained model and a and b are data points, then the following code computes the ranking:

bool a_better_than_b = (f(a) < f(b));

Definition at line 71 of file RankingSvmTrainer.h.

Member Typedef Documentation

◆ KernelType

template<class InputType , class CacheType = float>
typedef AbstractKernelFunction<InputType> shark::RankingSvmTrainer< InputType, CacheType >::KernelType

Definition at line 87 of file RankingSvmTrainer.h.

◆ QpFloatType

template<class InputType , class CacheType = float>
typedef CacheType shark::RankingSvmTrainer< InputType, CacheType >::QpFloatType

Convenience typedefs: this and many of the below typedefs build on the class template type CacheType. Simply changing that one template parameter CacheType thus allows to flexibly switch between using float or double as type for caching the kernel values. The default is float, offering sufficient accuracy in the vast majority of cases, at a memory cost of only four bytes. However, the template parameter makes it easy to use double instead, (e.g., in case high accuracy training is needed).

Definition at line 85 of file RankingSvmTrainer.h.

Constructor & Destructor Documentation

◆ RankingSvmTrainer()

template<class InputType , class CacheType = float>
shark::RankingSvmTrainer< InputType, CacheType >::RankingSvmTrainer ( KernelType kernel,
double  C,
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
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 93 of file RankingSvmTrainer.h.

Member Function Documentation

◆ name()

template<class InputType , class CacheType = float>
std::string shark::RankingSvmTrainer< InputType, CacheType >::name ( ) const
inlinevirtual

From INameable: return the class name.

Reimplemented from shark::INameable.

Definition at line 98 of file RankingSvmTrainer.h.

◆ train() [1/3]

template<class InputType , class CacheType = float>
void shark::RankingSvmTrainer< InputType, CacheType >::train ( KernelExpansion< InputType > &  function,
Data< InputType > const &  dataset 
)
inline

Train the ranking SVM.

This variant of the train function assumes that all pairs of points should be ranked according to the order they appear in the data set.

Definition at line 106 of file RankingSvmTrainer.h.

References shark::Data< Type >::numberOfElements().

Referenced by shark::RankingSvmTrainer< InputType, CacheType >::train().

◆ train() [2/3]

template<class InputType , class CacheType = float>
void shark::RankingSvmTrainer< InputType, CacheType >::train ( KernelExpansion< InputType > &  function,
LabeledData< InputType, unsigned int > const &  dataset 
)
inline

Train the ranking SVM.

This variant of the train function uses integer labels to define pairwise rankings. It is trained on all pairs of data points with different label, aiming for a smaller function value for the point with smaller label.

Definition at line 125 of file RankingSvmTrainer.h.

References shark::Data< Type >::elements(), shark::LabeledData< InputT, LabelT >::inputs(), shark::LabeledData< InputT, LabelT >::labels(), and shark::RankingSvmTrainer< InputType, CacheType >::train().

◆ train() [3/3]


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