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 (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, RealMatrixRow 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, RealMatrixRow &alpha, RealVector &mu)=0 |
| Solve the sub-problem posed by a single training example. More... | |
Protected Attributes | |
| DataView< const DatasetType > | m_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... | |
Generic solver skeleton for linear multi-class SVM problems.
Definition at line 64 of file QpMcLinear.h.
| typedef LabeledData<InputT, unsigned int> shark::QpMcLinear< InputT >::DatasetType |
Definition at line 67 of file QpMcLinear.h.
| typedef LabeledData<InputT, unsigned int>::const_element_reference shark::QpMcLinear< InputT >::ElementType |
Definition at line 68 of file QpMcLinear.h.
| typedef Batch<InputT>::const_reference shark::QpMcLinear< InputT >::InputReferenceType |
Definition at line 69 of file QpMcLinear.h.
| enum shark::QpMcLinear::CoordinateSelectionStrategy |
| Enumerator | |
|---|---|
| UNIFORM | |
| ACF | |
Definition at line 71 of file QpMcLinear.h.
|
inline |
Constructor.
| dataset | training data |
| dim | problem dimension |
| classes | number of classes in the problem |
| strategy | coordinate selection strategy |
| shrinking | flag turning shrinking on and off |
Definition at line 83 of file QpMcLinear.h.
References shark::blas::inner_prod(), shark::QpMcLinear< InputT >::m_data, shark::QpMcLinear< InputT >::m_dim, shark::QpMcLinear< InputT >::m_xSquared, and SHARK_ASSERT.
|
inlineprotected |
Definition at line 343 of file QpMcLinear.h.
References shark::QpMcLinear< InputT >::calcGradient(), shark::QpMcLinear< InputT >::m_classes, shark::blas::noalias(), shark::blas::row(), shark::QpMcLinear< InputT >::solveSub(), shark::QpMcLinear< InputT >::updateWeightVectors(), and w.
Referenced by shark::QpMcLinearWW< InputT >::updateWeightVectors(), shark::QpMcLinearLLW< InputT >::updateWeightVectors(), shark::QpMcLinearATS< InputT >::updateWeightVectors(), shark::QpMcLinearMMR< InputT >::updateWeightVectors(), shark::QpMcLinearCS< InputT >::updateWeightVectors(), shark::QpMcLinearADM< InputT >::updateWeightVectors(), shark::QpMcLinearATM< InputT >::updateWeightVectors(), and shark::QpMcLinearReinforced< InputT >::updateWeightVectors().
|
protectedpure virtual |
Compute the gradient from the inner products of the weight vectors with the current sample.
| gradient | gradient vector to be filled in. The vector is correctly sized. |
| wx | inner products of weight vectors with the current sample; wx(c) = <w_c, x> |
| alpha | variables corresponding to the current sample |
| C | upper bound on the variables |
| y | label of the current 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 >.
Referenced by shark::QpMcLinear< InputT >::add_scaled(), and shark::QpMcLinear< InputT >::solve().
|
inline |
Solve the SVM training problem.
| C | regularization constant of the SVM |
| stop | stopping condition(s) |
| prop | solution properties |
| verbose | if true, the solver prints status information and solution statistics |
Definition at line 112 of file QpMcLinear.h.
References shark::QpMcLinear< InputT >::calcGradient(), CHANGE_RATE, shark::discrete(), shark::Timer::lastLap(), shark::QpMcLinear< InputT >::m_classes, shark::QpMcLinear< InputT >::m_data, shark::QpMcLinear< InputT >::m_dim, shark::QpMcLinear< InputT >::m_shrinking, shark::QpMcLinear< InputT >::m_strategy, shark::QpMcLinear< InputT >::m_xSquared, shark::blas::max(), shark::QpStoppingCondition::maxIterations, shark::QpStoppingCondition::maxSeconds, shark::blas::min(), shark::QpStoppingCondition::minAccuracy, PREF_MAX, PREF_MIN, shark::blas::prod(), shark::QpAccuracyReached, shark::QpMaxIterationsReached, shark::QpTimeout, shark::blas::row(), SHARK_ASSERT, shark::QpMcLinear< InputT >::solveSub(), shark::Timer::start(), shark::Timer::stop(), shark::swap(), shark::uni(), shark::QpMcLinear< InputT >::UNIFORM, shark::QpMcLinear< InputT >::updateWeightVectors(), and w.
Referenced by shark::LinearMcSvmMMRTrainer< InputType >::train(), shark::LinearMcSvmReinforcedTrainer< InputType >::train(), shark::LinearMcSvmLLWTrainer< InputType >::train(), shark::LinearMcSvmADMTrainer< InputType >::train(), shark::LinearMcSvmATSTrainer< InputType >::train(), shark::LinearMcSvmATMTrainer< InputType >::train(), shark::LinearMcSvmCSTrainer< InputType >::train(), and shark::LinearMcSvmWWTrainer< InputType >::train().
|
protectedpure virtual |
Solve the sub-problem posed by a single training example.
| epsilon | accuracy (dual gradient) up to which the sub-problem should be solved |
| gradient | gradient of the objective function w.r.t. alpha |
| q | squared norm of the current sample |
| C | upper bound on the variables |
| y | label of the current sample |
| alpha | input: initial point; output: (near) optimal point |
| mu | step from initial point to final point |
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 >.
Referenced by shark::QpMcLinear< InputT >::add_scaled(), and shark::QpMcLinear< InputT >::solve().
|
protectedpure virtual |
Update the weight vectors (primal variables) after a step on the dual variables.
| w | matrix of (dense) weight vectors (as rows) |
| mu | dual step on the variables corresponding to the current sample |
| index | current 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 >.
Referenced by shark::QpMcLinear< InputT >::add_scaled(), and shark::QpMcLinear< InputT >::solve().
|
protected |
number of classes
Definition at line 382 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::add_scaled(), shark::QpMcLinearLLW< InputT >::calcGradient(), shark::QpMcLinearATS< InputT >::calcGradient(), shark::QpMcLinearMMR< InputT >::calcGradient(), shark::QpMcLinearCS< InputT >::calcGradient(), shark::QpMcLinearADM< InputT >::calcGradient(), shark::QpMcLinearATM< InputT >::calcGradient(), shark::QpMcLinearReinforced< InputT >::calcGradient(), shark::QpMcLinear< InputT >::solve(), shark::QpMcLinearWW< InputT >::solveSub(), shark::QpMcLinearLLW< InputT >::solveSub(), shark::QpMcLinearATS< InputT >::solveSub(), shark::QpMcLinearMMR< InputT >::solveSub(), shark::QpMcLinearCS< InputT >::solveSub(), shark::QpMcLinearADM< InputT >::solveSub(), shark::QpMcLinearATM< InputT >::solveSub(), shark::QpMcLinearReinforced< InputT >::solveSub(), shark::QpMcLinearWW< InputT >::updateWeightVectors(), shark::QpMcLinearLLW< InputT >::updateWeightVectors(), shark::QpMcLinearATS< InputT >::updateWeightVectors(), shark::QpMcLinearMMR< InputT >::updateWeightVectors(), shark::QpMcLinearCS< InputT >::updateWeightVectors(), shark::QpMcLinearADM< InputT >::updateWeightVectors(), shark::QpMcLinearATM< InputT >::updateWeightVectors(), and shark::QpMcLinearReinforced< InputT >::updateWeightVectors().
|
protected |
view on training data
Definition at line 379 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::QpMcLinear(), shark::QpMcLinear< InputT >::solve(), shark::QpMcLinearWW< InputT >::updateWeightVectors(), shark::QpMcLinearLLW< InputT >::updateWeightVectors(), shark::QpMcLinearATS< InputT >::updateWeightVectors(), shark::QpMcLinearMMR< InputT >::updateWeightVectors(), shark::QpMcLinearCS< InputT >::updateWeightVectors(), shark::QpMcLinearADM< InputT >::updateWeightVectors(), shark::QpMcLinearATM< InputT >::updateWeightVectors(), and shark::QpMcLinearReinforced< InputT >::updateWeightVectors().
|
protected |
input space dimension
Definition at line 381 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::QpMcLinear(), and shark::QpMcLinear< InputT >::solve().
|
protected |
apply shrinking or not?
Definition at line 384 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::solve().
|
protected |
strategy for coordinate selection
Definition at line 383 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::solve().
|
protected |
diagonal entries of the quadratic matrix
Definition at line 380 of file QpMcLinear.h.
Referenced by shark::QpMcLinear< InputT >::QpMcLinear(), and shark::QpMcLinear< InputT >::solve().