latest version v1.9 - last update 10 Apr 2010 |
Implements a support vector machine (SVM). More...
#include <ltiSVM.h>
Classes | |
class | parameters |
the parameters for the class svm More... | |
Public Member Functions | |
svm () | |
svm (const svm &other) | |
virtual | ~svm () |
virtual const char * | getTypeName () const |
svm & | copy (const svm &other) |
svm & | operator= (const svm &other) |
virtual classifier * | clone () const |
const parameters & | getParameters () const |
virtual bool | train (const dmatrix &input, const ivector &ids) |
virtual bool | train (const dmatrix &input, const ivector &ids, const std::map< int, kernelFunctor< double > * > &kernels) |
virtual bool | classify (const dvector &feature, outputVector &result) const |
void | getAlphas (dmatrix &result) const |
void | getBiases (dvector &result) const |
void | setKernel (const kernelFunctor< double > &k) |
void | attachKernel (kernelFunctor< double > *k) |
void | useExternalKernel (kernelFunctor< double > *k) |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Protected Member Functions | |
void | makeTargets (const ivector &ids) |
void | rebuildTargets () |
Implements a support vector machine (SVM).
The SVM is trained using the SMO algorithm (sequential minimal optimization) by J.C. Platt (presented at NIPS 1999).
The kernel function is determined by an object of type kernelFunctor<double>. svm contains an inner class called linearKernel which is the default. If your application requires another kernel function, you have to find one in another place.
lti::svm::svm | ( | ) |
default constructor
virtual lti::svm::~svm | ( | ) | [virtual] |
destructor
void lti::svm::attachKernel | ( | kernelFunctor< double > * | k | ) |
Sets a new kernel function.
The kernel which is passed here as an argument must have been allocated with new; it must not be a local variable. On destruction of the parameters object, the kernel will be deleted, i.e. the parameters instance will take control over the memory management of the kernel functor.
virtual bool lti::svm::classify | ( | const dvector & | feature, | |
outputVector & | result | |||
) | const [virtual] |
Classification.
Classifies the feature and returns the outputVector object with the classification result.
NOTE: This method is NOT really const. Although the main members of the svm are not changed some state variables used for efficiency are. Thus, it is not save to use the same instance of the svm in two different threads.
feature | pattern to be classified | |
result | of the classifications as a classifier::outputVector |
Implements lti::supervisedInstanceClassifier.
virtual classifier* lti::svm::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this clustering.
Implements lti::classifier.
copy data of "other" clustering.
other | the clustering to be copied |
Reimplemented from lti::supervisedInstanceClassifier.
void lti::svm::getAlphas | ( | dmatrix & | result | ) | const [inline] |
Returns the alpha matrix of the classifier.
The matrix contains one row for each class. Each row contains the alpha values of a SVM that distinguishes this class from all other classes.
void lti::svm::getBiases | ( | dvector & | result | ) | const [inline] |
Returns the bias vector of the classifier.
The vector contains the bias value for each class. Each element is the bias value of a SVM that distinguishes this class from all other classes.
const parameters& lti::svm::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::supervisedInstanceClassifier.
virtual const char* lti::svm::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("svm")
Reimplemented from lti::supervisedInstanceClassifier.
void lti::svm::makeTargets | ( | const ivector & | ids | ) | [protected] |
Copy the given ids to srcIds and build the target matrix.
alias for copy member
other | the clustering to be copied |
Reimplemented from lti::supervisedInstanceClassifier.
virtual bool lti::svm::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
read the classifier from the given ioHandler
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from lti::classifier.
void lti::svm::rebuildTargets | ( | ) | [protected] |
Rebuild the target matrix from srcIds.
void lti::svm::setKernel | ( | const kernelFunctor< double > & | k | ) |
Sets a new kernel function.
The kernel which is passed here will be copied, and the parameters instance will control the memory management.
virtual bool lti::svm::train | ( | const dmatrix & | input, | |
const ivector & | ids, | |||
const std::map< int, kernelFunctor< double > * > & | kernels | |||
) | [virtual] |
Supervised training.
The vectors in the input
matrix are arranged row-wise, i.e. each row contains one data vector. The ids
vector contains the class label for each row. This functor implements the SMO algorithm by J.C. Platt. Each class is modeled using a separate kernel function given by the kernels
map. This map consists of assignments of each class label to a kernelFunctor object. Care must be taken that the kernel functor object ist not deallocated while the SVM functor is in use.
input | the matrix with the input vectors (each row is a training vector) | |
ids | vector of class ids for each input point | |
kernels | map of kernel functions. Each functor uses |
Supervised training.
The vectors in the input
matrix are arranged row-wise, i.e. each row contains one data vector. The ids
vector contains the class label for each row. This functor implements the SMO algorithm by J.C. Platt. All classes are modeled using the same kernel function, given in the parameters object.
input | the matrix with the input vectors (each row is a training vector) | |
ids | vector of class ids for each input point |
Implements lti::supervisedInstanceClassifier.
void lti::svm::useExternalKernel | ( | kernelFunctor< double > * | k | ) |
Sets a new kernel function.
The kernel which is passed here as an argument is not deleted by the parameters object, the caller must ensure that there are no memory leaks.
virtual bool lti::svm::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
write the classifier in the given ioHandler
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from lti::classifier.