shark::QpMcSimplexDecomp< Matrix > Class Template Reference

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

Classes

struct  Example
 data structure describing one training example More...
 
struct  PreferedSelectionStrategy
 Working set selection eturning th S2DO working set. More...
 
struct  Variable
 data structure describing one variable of the problem More...
 

Public Types

typedef Matrix::QpFloatType QpFloatType
 

Public Member Functions

 QpMcSimplexDecomp (Matrix &kernel, QpSparseArray< QpFloatType > const &M, Data< unsigned int > const &target, RealMatrix const &linearMat, double C)
 
void setShrinking (bool shrinking=true)
 enable/disable shrinking More...
 
RealMatrix solution () const
 Returns the solution found. More...
 
RealMatrix solutionGradient () const
 Returns the gradient of the solution. More...
 
double functionValue () const
 Compute the objective value of the current solution. More...
 
unsigned int label (std::size_t i)
 
std::size_t dimensions () const
 
std::size_t cardP () const
 
std::size_t getNumExamples () const
 
void addDeltaLinear (RealMatrix const &deltaLinear)
 change the linear part of the problem by some delta More...
 
void updateSMO (std::size_t v, std::size_t w)
 
bool shrink (double epsilon)
 Shrink the problem. More...
 
void unshrink ()
 Activate all m_numVariables. More...
 
double selectWorkingSet (std::size_t &i, std::size_t &j)
 select the working set More...
 
double checkKKT () const
 return the largest KKT violation More...
 

Protected Member Functions

std::pair< std::pair< std::size_t, std::size_t >, double > maxGainBox (std::size_t i) const
 Finds the second variable of a working set using maximum gain and returns the pair and gain. More...
 
std::pair< std::pair< std::size_t, std::size_t >, double > maxGainSimplex (std::size_t e) const
 Returns the best variable pair (i,j) and gain for a given example. More...
 
std::pair< std::pair< double, std::size_t >, std::pair< double, std::size_t > > getSimplexMVP (Example const &ex) const
 For a given simplex returns the MVP indicies (max_up,min_down) More...
 
void updateVarsum (std::size_t exampleId, double mu)
 
void gradientUpdate (std::size_t r, double mu, QpFloatType *q)
 
void deactivateVariable (std::size_t v)
 shrink a variable More...
 
void deactivateExample (std::size_t e)
 shrink an example More...
 
std::size_t originalIndex (std::size_t v) const
 Returns the original index of the example of a variable in the dataset before optimization. More...
 

Protected Attributes

Matrix & m_kernelMatrix
 kernel matrix (precomputed matrix or matrix cache) More...
 
QpSparseArray< QpFloatType > const & m_M
 kernel modifiers More...
 
double m_C
 complexity constant; upper bound on all variabless More...
 
std::size_t m_classes
 number of classes in the problem More...
 
std::size_t m_cardP
 number of dual variables per example More...
 
std::size_t m_numExamples
 number of examples in the problem (size of the kernel matrix) More...
 
std::size_t m_numVariables
 number of variables in the problem = m_numExamples * m_cardP More...
 
RealVector m_linear
 linear part of the objective function More...
 
RealVector m_alpha
 solution candidate More...
 
RealVector m_gradient
 
std::vector< Examplem_examples
 information about each training example More...
 
std::vector< Variablem_variables
 information about each variable of the problem More...
 
std::vector< std::size_t > m_storage1
 space for the example[i].var pointers More...
 
std::vector< std::size_t > m_storage2
 space for the example[i].avar pointers More...
 
std::size_t m_activeEx
 number of currently active examples More...
 
std::size_t m_activeVar
 number of currently active variables More...
 
bool m_useShrinking
 should the m_problem use the shrinking heuristics? More...
 
bool bUnshrinked
 true if the problem has already been unshrinked More...
 

Detailed Description

template<class Matrix>
class shark::QpMcSimplexDecomp< Matrix >

Definition at line 50 of file QpMcSimplexDecomp.h.

Member Typedef Documentation

◆ QpFloatType

template<class Matrix>
typedef Matrix::QpFloatType shark::QpMcSimplexDecomp< Matrix >::QpFloatType

Definition at line 53 of file QpMcSimplexDecomp.h.

Constructor & Destructor Documentation

◆ QpMcSimplexDecomp()

Member Function Documentation

◆ addDeltaLinear()

◆ cardP()

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::cardP ( ) const
inline

◆ checkKKT()

template<class Matrix>
double shark::QpMcSimplexDecomp< Matrix >::checkKKT ( ) const
inline

◆ deactivateExample()

◆ deactivateVariable()

◆ dimensions()

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::dimensions ( ) const
inline

◆ functionValue()

template<class Matrix>
double shark::QpMcSimplexDecomp< Matrix >::functionValue ( ) const
inline

Compute the objective value of the current solution.

Definition at line 156 of file QpMcSimplexDecomp.h.

◆ getNumExamples()

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::getNumExamples ( ) const
inline

◆ getSimplexMVP()

template<class Matrix>
std::pair< std::pair<double,std::size_t>, std::pair<double,std::size_t> > shark::QpMcSimplexDecomp< Matrix >::getSimplexMVP ( Example const &  ex) const
inlineprotected

◆ gradientUpdate()

template<class Matrix>
void shark::QpMcSimplexDecomp< Matrix >::gradientUpdate ( std::size_t  r,
double  mu,
QpFloatType q 
)
inlineprotected

◆ label()

template<class Matrix>
unsigned int shark::QpMcSimplexDecomp< Matrix >::label ( std::size_t  i)
inline

◆ maxGainBox()

template<class Matrix>
std::pair<std::pair<std::size_t,std::size_t>,double> shark::QpMcSimplexDecomp< Matrix >::maxGainBox ( std::size_t  i) const
inlineprotected

Finds the second variable of a working set using maximum gain and returns the pair and gain.

The variable is searched in-between samples. And not inside the simplex of i. It returns the best pair (i,j) as well as the gain. If the first variable can't make a step, gain 0 is returned with pair(i,i).

Definition at line 529 of file QpMcSimplexDecomp.h.

References shark::QpMcSimplexDecomp< Matrix >::m_activeEx, shark::QpMcSimplexDecomp< Matrix >::m_C, shark::QpMcSimplexDecomp< Matrix >::m_examples, shark::QpMcSimplexDecomp< Matrix >::m_gradient, shark::QpMcSimplexDecomp< Matrix >::m_kernelMatrix, shark::QpMcSimplexDecomp< Matrix >::m_variables, SHARK_ASSERT, shark::QpMcSimplexDecomp< Matrix >::Example::varsum, and shark::QpMcSimplexDecomp< Matrix >::Example::y.

Referenced by shark::QpMcSimplexDecomp< Matrix >::selectWorkingSet().

◆ maxGainSimplex()

template<class Matrix>
std::pair<std::pair<std::size_t,std::size_t>,double> shark::QpMcSimplexDecomp< Matrix >::maxGainSimplex ( std::size_t  e) const
inlineprotected

◆ originalIndex()

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::originalIndex ( std::size_t  v) const
inlineprotected

Returns the original index of the example of a variable in the dataset before optimization.

Shrinking is an internal detail so the communication with the outside world uses the original indizes.

Definition at line 823 of file QpMcSimplexDecomp.h.

References shark::QpMcSimplexDecomp< Matrix >::m_examples, and shark::QpMcSimplexDecomp< Matrix >::m_variables.

Referenced by shark::QpMcSimplexDecomp< Matrix >::addDeltaLinear(), shark::QpMcSimplexDecomp< Matrix >::solution(), and shark::QpMcSimplexDecomp< Matrix >::solutionGradient().

◆ selectWorkingSet()

template<class Matrix>
double shark::QpMcSimplexDecomp< Matrix >::selectWorkingSet ( std::size_t &  i,
std::size_t &  j 
)
inline

select the working set

Select one or two numVariables for the sub-problem and return the maximal KKT violation. The method MAY select the same index for i and j. In that case the working set consists of a single variables. The working set may be invalid if the method reports a KKT violation of zero, indicating optimality.

Definition at line 406 of file QpMcSimplexDecomp.h.

References shark::QpMcSimplexDecomp< Matrix >::getSimplexMVP(), shark::QpMcSimplexDecomp< Matrix >::m_activeEx, shark::QpMcSimplexDecomp< Matrix >::m_C, shark::QpMcSimplexDecomp< Matrix >::m_examples, shark::QpMcSimplexDecomp< Matrix >::m_variables, shark::QpMcSimplexDecomp< Matrix >::maxGainBox(), shark::QpMcSimplexDecomp< Matrix >::maxGainSimplex(), and shark::QpMcSimplexDecomp< Matrix >::Example::varsum.

◆ setShrinking()

template<class Matrix>
void shark::QpMcSimplexDecomp< Matrix >::setShrinking ( bool  shrinking = true)
inline

enable/disable shrinking

Definition at line 131 of file QpMcSimplexDecomp.h.

References shark::QpMcSimplexDecomp< Matrix >::m_useShrinking.

◆ shrink()

◆ solution()

◆ solutionGradient()

◆ unshrink()

template<class Matrix>
void shark::QpMcSimplexDecomp< Matrix >::unshrink ( )
inline

◆ updateSMO()

◆ updateVarsum()

template<class Matrix>
void shark::QpMcSimplexDecomp< Matrix >::updateVarsum ( std::size_t  exampleId,
double  mu 
)
inlineprotected

Member Data Documentation

◆ bUnshrinked

template<class Matrix>
bool shark::QpMcSimplexDecomp< Matrix >::bUnshrinked
protected

true if the problem has already been unshrinked

Definition at line 881 of file QpMcSimplexDecomp.h.

Referenced by shark::QpMcSimplexDecomp< Matrix >::QpMcSimplexDecomp(), and shark::QpMcSimplexDecomp< Matrix >::shrink().

◆ m_activeEx

◆ m_activeVar

◆ m_alpha

◆ m_C

◆ m_cardP

◆ m_classes

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::m_classes
protected

number of classes in the problem

Definition at line 838 of file QpMcSimplexDecomp.h.

Referenced by shark::QpMcSimplexDecomp< Matrix >::QpMcSimplexDecomp(), and shark::QpMcSimplexDecomp< Matrix >::updateSMO().

◆ m_examples

◆ m_gradient

◆ m_kernelMatrix

template<class Matrix>
Matrix& shark::QpMcSimplexDecomp< Matrix >::m_kernelMatrix
protected

◆ m_linear

template<class Matrix>
RealVector shark::QpMcSimplexDecomp< Matrix >::m_linear
protected

◆ m_M

template<class Matrix>
QpSparseArray<QpFloatType> const& shark::QpMcSimplexDecomp< Matrix >::m_M
protected

◆ m_numExamples

template<class Matrix>
std::size_t shark::QpMcSimplexDecomp< Matrix >::m_numExamples
protected

◆ m_numVariables

◆ m_storage1

template<class Matrix>
std::vector<std::size_t> shark::QpMcSimplexDecomp< Matrix >::m_storage1
protected

space for the example[i].var pointers

Definition at line 866 of file QpMcSimplexDecomp.h.

Referenced by shark::QpMcSimplexDecomp< Matrix >::QpMcSimplexDecomp().

◆ m_storage2

template<class Matrix>
std::vector<std::size_t> shark::QpMcSimplexDecomp< Matrix >::m_storage2
protected

space for the example[i].avar pointers

Definition at line 869 of file QpMcSimplexDecomp.h.

Referenced by shark::QpMcSimplexDecomp< Matrix >::QpMcSimplexDecomp().

◆ m_useShrinking

template<class Matrix>
bool shark::QpMcSimplexDecomp< Matrix >::m_useShrinking
protected

should the m_problem use the shrinking heuristics?

Definition at line 878 of file QpMcSimplexDecomp.h.

Referenced by shark::QpMcSimplexDecomp< Matrix >::setShrinking(), and shark::QpMcSimplexDecomp< Matrix >::shrink().

◆ m_variables


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