LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::svm Class Reference

Implements a support vector machine (SVM). More...

#include <ltiSVM.h>

Inheritance diagram for lti::svm:
Inheritance graph
[legend]
Collaboration diagram for lti::svm:
Collaboration graph
[legend]

List of all members.

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
svmcopy (const svm &other)
svmoperator= (const svm &other)
virtual classifierclone () const
const parametersgetParameters () 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 ()

Detailed Description

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.


Constructor & Destructor Documentation

lti::svm::svm (  ) 

default constructor

lti::svm::svm ( const svm other  ) 

copy constructor

Parameters:
other the object to be copied
virtual lti::svm::~svm (  )  [virtual]

destructor


Member Function Documentation

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.

Parameters:
feature pattern to be classified
result of the classifications as a classifier::outputVector
Returns:
true if the classification has been successful

Implements lti::supervisedInstanceClassifier.

virtual classifier* lti::svm::clone (  )  const [virtual]

returns a pointer to a clone of this clustering.

Implements lti::classifier.

svm& lti::svm::copy ( const svm other  ) 

copy data of "other" clustering.

Parameters:
other the clustering to be copied
Returns:
a reference to this clustering object

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.

svm& lti::svm::operator= ( const svm other  ) 

alias for copy member

Parameters:
other the clustering to be copied
Returns:
a reference to this clustering object

Reimplemented from lti::supervisedInstanceClassifier.

virtual bool lti::svm::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

read the classifier from the given ioHandler

Parameters:
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.
Returns:
true if write was successful

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.

Parameters:
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
Returns:
true if successful, false otherwise. (if false you can check the error message with getStatusString())
virtual bool lti::svm::train ( const dmatrix input,
const ivector ids 
) [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. All classes are modeled using the same kernel function, given in the parameters object.

Parameters:
input the matrix with the input vectors (each row is a training vector)
ids vector of class ids for each input point
Returns:
true if successful, false otherwise. (if false you can check the error message with getStatusString())

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

Parameters:
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.
Returns:
true if write was successful

Reimplemented from lti::classifier.


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

Generated on Sat Apr 10 15:27:01 2010 for LTI-Lib by Doxygen 1.6.1