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, unsignedint >::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. | |
| RealMatrix | solve (random::rng_type &rng, double C, QpStoppingCondition &stop, QpSolutionProperties *prop=NULL, bool verbose=false) |
| Solve the SVM training problem. | |
Protected Member Functions | |
| void | add_scaled (RealMatrix &w, RealVector const &mu, InputReferenceType x) |
| virtual double | calcGradient (RealVector &gradient, RealVector wx, blas::dense_vector_adaptor< double const > const &alpha, double C, unsigned int y)=0 |
| Compute the gradient from the inner products of the weight vectors with the current sample. | |
| 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. | |
| virtual double | solveSub (double epsilon, RealVector &gradient, double q, double C, unsigned int y, blas::dense_vector_adaptor< double > &alpha, RealVector &mu)=0 |
| Solve the sub-problem posed by a single training example. | |
Protected Attributes | |
| DataView< const DatasetType > | m_data |
| view on training data | |
| RealVector | m_xSquared |
| diagonal entries of the quadratic matrix | |
| std::size_t | m_dim |
| input space dimension | |
| std::size_t | m_classes |
| number of classes | |
| std::size_t | m_strategy |
| strategy for coordinate selection | |
| bool | m_shrinking |
| apply shrinking or not? | |
Generic solver skeleton for linear multi-class SVM problems.
Definition at line 54 of file QpMcLinear.h.
| typedef LabeledData<InputT, unsigned int> shark::QpMcLinear< InputT >::DatasetType |
Definition at line 57 of file QpMcLinear.h.
| typedef LabeledData<InputT,unsignedint>::const_element_reference shark::QpMcLinear< InputT >::ElementType |
Definition at line 58 of file QpMcLinear.h.
| typedef Batch<InputT>::const_reference shark::QpMcLinear< InputT >::InputReferenceType |
Definition at line 59 of file QpMcLinear.h.
| enum shark::QpMcLinear::CoordinateSelectionStrategy |
| Enumerator | |
|---|---|
| UNIFORM | |
| ACF | |
Definition at line 61 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 73 of file QpMcLinear.h.
References 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 >::m_classes.
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::QpMcLinearWW< InputT >, shark::QpMcLinearLLW< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearATM< InputT >, and shark::QpMcLinearReinforced< InputT >.
Referenced by shark::QpMcLinear< InputT >::solve().
|
inline |
Solve the SVM training problem.
| rng | random number generator used by the algorithm |
| 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 103 of file QpMcLinear.h.
References shark::QpMcLinear< InputT >::ACF, shark::QpMcLinear< InputT >::calcGradient(), 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::QpStoppingCondition::maxIterations, shark::QpStoppingCondition::maxSeconds, shark::QpStoppingCondition::minAccuracy, shark::QpAccuracyReached, shark::QpMaxIterationsReached, shark::QpTimeout, SHARK_ASSERT, shark::QpMcLinear< InputT >::solveSub(), shark::Timer::start(), shark::Timer::stop(), shark::random::uni(), shark::QpMcLinear< InputT >::UNIFORM, and shark::QpMcLinear< InputT >::updateWeightVectors().
|
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::QpMcLinearWW< InputT >, shark::QpMcLinearLLW< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearATM< InputT >, and shark::QpMcLinearReinforced< InputT >.
Referenced by 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::QpMcLinearWW< InputT >, shark::QpMcLinearLLW< InputT >, shark::QpMcLinearATS< InputT >, shark::QpMcLinearMMR< InputT >, shark::QpMcLinearCS< InputT >, shark::QpMcLinearADM< InputT >, shark::QpMcLinearATM< InputT >, and shark::QpMcLinearReinforced< InputT >.
Referenced by 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().