shark::QpMcLinear< InputT > Class Template Referenceabstract

Generic solver skeleton for linear multi-class SVM problems. More...

#include <shark/Algorithms/QP/QpMcLinear.h>

+ Inheritance diagram for shark::QpMcLinear< InputT >:

Public Types

enum  CoordinateSelectionStrategy { UNIFORM, ACF }
 
typedef LabeledData< InputT, unsigned int > DatasetType
 
typedef LabeledData< InputT, unsigned int >::const_element_reference ElementType
 
typedef Batch< InputT >::const_reference InputReferenceType
 

Public Member Functions

 QpMcLinear (const DatasetType &dataset, std::size_t dim, std::size_t classes, std::size_t strategy=ACF, bool shrinking=false)
 Constructor. More...
 
RealMatrix solve (random::rng_type &rng, double C, QpStoppingCondition &stop, QpSolutionProperties *prop=NULL, bool verbose=false)
 Solve the SVM training problem. More...
 

Protected Member Functions

void add_scaled (RealMatrix &w, RealVector const &mu, InputReferenceType x)
 
virtual double calcGradient (RealVector &gradient, RealVector wx, blas::matrix_row< RealMatrix > const &alpha, double C, unsigned int y)=0
 Compute the gradient from the inner products of the weight vectors with the current sample. More...
 
virtual void updateWeightVectors (RealMatrix &w, RealVector const &mu, std::size_t index)=0
 Update the weight vectors (primal variables) after a step on the dual variables. More...
 
virtual double solveSub (double epsilon, RealVector gradient, double q, double C, unsigned int y, blas::matrix_row< RealMatrix > &alpha, RealVector &mu)=0
 Solve the sub-problem posed by a single training example. More...
 

Protected Attributes

DataView< const DatasetTypem_data
 view on training data More...
 
RealVector m_xSquared
 diagonal entries of the quadratic matrix More...
 
std::size_t m_dim
 input space dimension More...
 
std::size_t m_classes
 number of classes More...
 
std::size_t m_strategy
 strategy for coordinate selection More...
 
bool m_shrinking
 apply shrinking or not? More...
 

Detailed Description

template<class InputT>
class shark::QpMcLinear< InputT >

Generic solver skeleton for linear multi-class SVM problems.

Definition at line 54 of file QpMcLinear.h.

Member Typedef Documentation

◆ DatasetType

template<class InputT >
typedef LabeledData<InputT, unsigned int> shark::QpMcLinear< InputT >::DatasetType

Definition at line 57 of file QpMcLinear.h.

◆ ElementType

template<class InputT >
typedef LabeledData<InputT, unsigned int>::const_element_reference shark::QpMcLinear< InputT >::ElementType

Definition at line 58 of file QpMcLinear.h.

◆ InputReferenceType

template<class InputT >
typedef Batch<InputT>::const_reference shark::QpMcLinear< InputT >::InputReferenceType

Definition at line 59 of file QpMcLinear.h.

Member Enumeration Documentation

◆ CoordinateSelectionStrategy

template<class InputT >
enum shark::QpMcLinear::CoordinateSelectionStrategy
Enumerator
UNIFORM 
ACF 

Definition at line 61 of file QpMcLinear.h.

Constructor & Destructor Documentation

◆ QpMcLinear()

template<class InputT >
shark::QpMcLinear< InputT >::QpMcLinear ( const DatasetType dataset,
std::size_t  dim,
std::size_t  classes,
std::size_t  strategy = ACF,
bool  shrinking = false 
)
inline

Constructor.

Parameters
datasettraining data
dimproblem dimension
classesnumber of classes in the problem
strategycoordinate selection strategy
shrinkingflag turning shrinking on and off

Definition at line 73 of file QpMcLinear.h.

References shark::QpMcLinear< InputT >::m_data, shark::QpMcLinear< InputT >::m_dim, shark::QpMcLinear< InputT >::m_xSquared, and SHARK_ASSERT.

Member Function Documentation

◆ add_scaled()

◆ calcGradient()

template<class InputT >
virtual double shark::QpMcLinear< InputT >::calcGradient ( RealVector &  gradient,
RealVector  wx,
blas::matrix_row< RealMatrix > const &  alpha,
double  C,
unsigned int  y 
)
protectedpure virtual

Compute the gradient from the inner products of the weight vectors with the current sample.

Parameters
gradientgradient vector to be filled in. The vector is correctly sized.
wxinner products of weight vectors with the current sample; wx(c) = <w_c, x>
alphavariables corresponding to the current sample
Cupper bound on the variables
ylabel of the current sample
Returns
The function must return the violation of the KKT conditions.

Implemented in shark::QpMcLinearReinforced< InputT >, shark::QpMcLinearATM< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearLLW< InputT >, and shark::QpMcLinearWW< InputT >.

◆ solve()

template<class InputT >
RealMatrix shark::QpMcLinear< InputT >::solve ( random::rng_type &  rng,
double  C,
QpStoppingCondition stop,
QpSolutionProperties prop = NULL,
bool  verbose = false 
)
inline

Solve the SVM training problem.

Parameters
rngrandom number generator used by the algorithm
Cregularization constant of the SVM
stopstopping condition(s)
propsolution properties
verboseif true, the solver prints status information and solution statistics

Definition at line 103 of file QpMcLinear.h.

References shark::QpMcLinear< InputT >::m_classes, shark::QpMcLinear< InputT >::m_data, shark::QpMcLinear< InputT >::m_dim, shark::QpMcLinear< InputT >::m_strategy, SHARK_ASSERT, shark::Timer::start(), shark::QpMcLinear< InputT >::UNIFORM, and w.

◆ solveSub()

template<class InputT >
virtual double shark::QpMcLinear< InputT >::solveSub ( double  epsilon,
RealVector  gradient,
double  q,
double  C,
unsigned int  y,
blas::matrix_row< RealMatrix > &  alpha,
RealVector &  mu 
)
protectedpure virtual

Solve the sub-problem posed by a single training example.

Parameters
epsilonaccuracy (dual gradient) up to which the sub-problem should be solved
gradientgradient of the objective function w.r.t. alpha
qsquared norm of the current sample
Cupper bound on the variables
ylabel of the current sample
alphainput: initial point; output: (near) optimal point
mustep from initial point to final point
Returns
The function must return the gain of the step, i.e., the improvement of the objective function.

Implemented in shark::QpMcLinearReinforced< InputT >, shark::QpMcLinearATM< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearLLW< InputT >, and shark::QpMcLinearWW< InputT >.

◆ updateWeightVectors()

template<class InputT >
virtual void shark::QpMcLinear< InputT >::updateWeightVectors ( RealMatrix &  w,
RealVector const &  mu,
std::size_t  index 
)
protectedpure virtual

Update the weight vectors (primal variables) after a step on the dual variables.

Parameters
wmatrix of (dense) weight vectors (as rows)
mudual step on the variables corresponding to the current sample
indexcurrent sample

Implemented in shark::QpMcLinearReinforced< InputT >, shark::QpMcLinearATM< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearLLW< InputT >, and shark::QpMcLinearWW< InputT >.

Member Data Documentation

◆ m_classes

◆ m_data

◆ m_dim

template<class InputT >
std::size_t shark::QpMcLinear< InputT >::m_dim
protected

input space dimension

Definition at line 381 of file QpMcLinear.h.

Referenced by shark::QpMcLinear< InputT >::QpMcLinear(), and shark::QpMcLinear< InputT >::solve().

◆ m_shrinking

template<class InputT >
bool shark::QpMcLinear< InputT >::m_shrinking
protected

apply shrinking or not?

Definition at line 384 of file QpMcLinear.h.

◆ m_strategy

template<class InputT >
std::size_t shark::QpMcLinear< InputT >::m_strategy
protected

strategy for coordinate selection

Definition at line 383 of file QpMcLinear.h.

Referenced by shark::QpMcLinear< InputT >::solve().

◆ m_xSquared

template<class InputT >
RealVector shark::QpMcLinear< InputT >::m_xSquared
protected

diagonal entries of the quadratic matrix

Definition at line 380 of file QpMcLinear.h.

Referenced by shark::QpMcLinear< InputT >::QpMcLinear().


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