Support Vector Machine algorithm for binary classifcation.
More...
#include <CSVM.h>
|
| CSVM (TSVMType=L1SVM) |
|
| ~CSVM () |
|
void | setMaxIterations (long lMax) |
|
void | classify (const CVector< Type > &tVec, Type *ptClass, Type *ptMargin) const |
|
void | classify (const CVector< Type > &tVec, Type &rtClass, Type &rtMargin) const |
|
void | classify (Type *ptVec, Type *ptClass, Type *ptMargin) const |
|
int | classify (const CVector< Type > &tVec) const |
|
string | className () const |
|
bool | isA (const char *acClass) const |
|
void | train (const CDataset< Type > &tTrainSet) |
|
void | setRegularization (Type tC) |
|
void | setWeight (Type tWPos, Type tWNeg) |
|
void | setTerminationError (Type tMinError) |
|
void | trainChunking (CDataset< Type > &rtTrainset, int iStartSetSize, int iMaxChunkSize) |
|
void | setKernel (CKernel< Type > *ptKernel) |
|
const CKernel< Type > * | kernel () |
|
void | setCacheSize (Type tSize) |
|
CDataset< Type > | getSupportData (bool bDropNonSV) |
|
CDataset< Type > | getNonSupportData () const |
|
CDenseVector< Type > | getWeightVector () const |
|
Type | bias () const |
|
bool | serialize (fstream &stream, IO_MODE mode) |
|
bool | serialize2 (CArchiv &tA) |
|
template<class Type>
class CSVM< Type >
Support Vector Machine algorithm for binary classifcation.
Solves the binary SVM training by decomposition. This implementation allows L1 and L2 penalties, class specific regularization, kernel caching and shrinking. The implementation is strongly inspired by libsvm but is much more readable. You can find more information about the implementation details in papers about Sequential Minimal Optimization and libsvm.
- Author
- Thorsten Twellmann (ttwel.nosp@m.lma@.nosp@m.TechF.nosp@m.ak.U.nosp@m.ni-Bi.nosp@m.elef.nosp@m.eld.d.nosp@m.e)
Constructor - Creates a new instance of a SVM with given penalty metric
- Parameters
-
tSVMType | Type of svm (default: L1SVM). |
template<class Type >
void CSVM< Type >::analyticSolve |
( |
int |
i1, |
|
|
int |
i2 |
|
) |
| |
|
protected |
Derive analytical solution with respect to i1 and i2
- Parameters
-
i1 | Workingset index |
i2 | Workingset index |
template<class Type >
Type CSVM< Type >::bias |
( |
| ) |
const |
|
inline |
template<class Type >
Type CSVM< Type >::calculateBias |
( |
| ) |
|
|
protected |
Calculate bias for trained svm
- Returns
- New bias value
template<class Type >
bool CSVM< Type >::checkShrinking |
( |
int |
, |
|
|
int |
|
|
) |
| |
|
protected |
template<class Type >
void CSVM< Type >::classify |
( |
const CVector< Type > & |
tVec, |
|
|
Type * |
ptClass, |
|
|
Type * |
ptMargin |
|
) |
| const |
Classifies a given pattern.
- Parameters
-
tVec | Vector containing the pattern to classify. |
ptClass | Pointer to variable which will be filled with the classlable. |
ptMargin | Pointer to variable which will be filled with calculated margin. |
template<class Type >
void CSVM< Type >::classify |
( |
const CVector< Type > & |
tVec, |
|
|
Type & |
rtClass, |
|
|
Type & |
rtMargin |
|
) |
| const |
template<class Type >
void CSVM< Type >::classify |
( |
Type * |
ptVec, |
|
|
Type * |
ptClass, |
|
|
Type * |
ptMargin |
|
) |
| const |
Classifies a given pattern.
- Parameters
-
ptVec | Array containing the pattern to classify. |
ptClass | Pointer to variable which will be filled with the classlable. |
ptMargin | Pointer to variable which will be filled with calculated margin. |
template<class Type >
int CSVM< Type >::classify |
( |
const CVector< Type > & |
tVec | ) |
const |
template<class Type >
string CSVM< Type >::className |
( |
| ) |
const |
|
inline |
template<class Type >
CDataset<Type> CSVM< Type >::getSupportData |
( |
bool |
bDropNonSV | ) |
|
Returns the svm solution as a dataset. The input vector of each item contains the training pattern. The output vector contains the class label (element 0) and the lagrange coefficient (element 1). By setting the parameter bDropNonSV=true, training vectors with lagrange coefficient equal to zero will be deleted.
- Parameters
-
bDropNonSV | If true, non-support vectors will be deleted |
- Returns
- Dataset containing support data
template<class Type >
void CSVM< Type >::init |
( |
| ) |
|
|
protected |
Initialize algorithm with given dataset
- Parameters
-
template<class Type >
bool CSVM< Type >::isA |
( |
const char * |
acClass | ) |
const |
|
inline |
Return const pointer to kernel object
- Returns
- Const pointer to kernel object
References CSVM< Type >::ptKernel.
template<class Type >
Type CSVM< Type >::l1Regularizer |
( |
Type |
tClass | ) |
|
|
inlineprotected |
template<class Type >
Type CSVM< Type >::l2Regularizer |
( |
Type |
tClass | ) |
|
|
inlineprotected |
template<class Type >
void CSVM< Type >::optimizeWorkingSet |
( |
| ) |
|
|
protected |
Train the algorithm with the current trainset
template<class Type >
void CSVM< Type >::rebuildGradient |
( |
| ) |
|
|
protected |
Recalculate the gradient
for all training examples.
template<class Type >
bool CSVM< Type >::selectPair |
( |
int * |
piI1, |
|
|
int * |
piI2, |
|
|
Type & |
tError |
|
) |
| |
|
protected |
template<class Type >
bool CSVM< Type >::serialize |
( |
fstream & |
stream, |
|
|
IO_MODE |
mode |
|
) |
| |
template<class Type >
void CSVM< Type >::setCacheSize |
( |
Type |
tSize | ) |
|
|
inline |
template<class Type >
void CSVM< Type >::setKernel |
( |
CKernel< Type > * |
ptKernel | ) |
|
Use a new kernel object. The SVM becomes the owner of the kernel object and will delete it in destruction.
- Parameters
-
ptKernel | Pointer to new kernel object |
template<class Type >
void CSVM< Type >::setMaxIterations |
( |
long |
lMax | ) |
|
|
inline |
template<class Type >
void CSVM< Type >::setRegularization |
( |
Type |
tC | ) |
|
Sets regularization paramert C. C will be the upper bound for the lagrange coefficients of the svm in case of L1 penalty and an additional term on the kernel in case of L2 penalty.
- Parameters
-
tC | New regularization value. |
template<class Type >
void CSVM< Type >::setTerminationError |
( |
Type |
tMinError | ) |
|
|
inline |
Sets the termination error. SVM training will terminate if the maximal difference between two lagrange gradients will drop below this threshold.
- Parameters
-
tMinError | Termination error. |
References CSVM< Type >::tTerminationError.
template<class Type >
void CSVM< Type >::setWeight |
( |
Type |
tWPos, |
|
|
Type |
tWNeg |
|
) |
| |
template<class Type >
void CSVM< Type >::train |
( |
const CDataset< Type > & |
tTrainSet | ) |
|
template<class Type >
void CSVM< Type >::trainChunking |
( |
CDataset< Type > & |
rtTrainset, |
|
|
int |
iStartSetSize, |
|
|
int |
iMaxChunkSize |
|
) |
| |
template<class Type >
void CSVM< Type >::updateGradient |
( |
int & |
a, |
|
|
double & |
tDeltaA, |
|
|
int & |
b, |
|
|
double & |
tDeltaB |
|
) |
| |
|
protected |
Update the gradient of the active items
using
- Parameters
-
a | Workingset index |
dDeltaA | Alpha change of a |
b | Workingset index |
dDeltaB | Alpha change of b |
template<class Type >
bool CSVM< Type >::bFoldKernel |
|
protected |
If true, the linear kernel is folded to a single vector describing the hyperplane
template<class Type >
bool CSVM< Type >::bUnshrinked |
|
protected |
template<class Type >
int CSVM< Type >::iCacheSize |
|
protected |
template<class Type >
int CSVM< Type >::iNumActiveItems |
|
protected |
Current number of active items
template<class Type >
int CSVM< Type >::iNumIteration |
|
protected |
Current number of iterations
template<class Type >
long CSVM< Type >::lMaxIterations |
|
protected |
template<class Type >
long CSVM< Type >::lNextShrink |
|
protected |
Cache for the kernelmatrix
Regularization parameter for L1-SVM
template<class Type >
Type CSVM< Type >::tTerminationError |
|
protected |
template<class Type >
vector<int> CSVM< Type >::tTransformedAccess |
|
protected |
template<class Type >
Type CSVM< Type >::tWeightNeg |
|
protected |
template<class Type >
Type CSVM< Type >::tWeightPos |
|
protected |
The documentation for this class was generated from the following file: