CSVM Class Reference

Inheritance diagram for CSVM:

Inheritance graph
[legend]

List of all members.


Detailed Description

A generic Support Vector Machine Interface

A support vector machine is defined as

\[ f({\bf x})=\sum_{i=0}^{N-1} \alpha_i k({\bf x}, {\bf x_i})+b \]

where $N$ is the number of training examples $\alpha_i$ are the weights assigned to each training example $k(x,x')$ is the kernel and $b$ the bias.

Using an a-priori choosen kernel, the $\alpha_i$ and bias are determined by solving the following quadratic program

\begin{eqnarray*} \max_{\bf \alpha} && \sum_{i=0}^{N-1} \alpha_i - \sum_{i=0}^{N-1}\sum_{j=0}^{N-1} \alpha_i y_i \alpha_j y_j k({\bf x_i}, {\bf x_j})\\ \mbox{s.t.} && 0\leq\alpha_i\leq C\\ && \sum_{i=0}^{N-1} \alpha_i y_i=0\\ \end{eqnarray*}

here C is a pre-specified regularization parameter.

Definition at line 43 of file SVM.h.


Public Member Functions

 CSVM (INT num_sv=0)
 CSVM (DREAL C, CKernel *k, CLabels *lab)
virtual ~CSVM ()
void set_defaults (INT num_sv=0)
bool load (FILE *svm_file)
bool save (FILE *svm_file)
void set_nu (DREAL nue)
void set_C (DREAL c1, DREAL c2)
void set_weight_epsilon (DREAL eps)
void set_epsilon (DREAL eps)
void set_tube_epsilon (DREAL eps)
void set_C_mkl (DREAL C)
void set_qpsize (INT qps)
void set_bias_enabled (bool enable_bias)
bool get_bias_enabled ()
DREAL get_weight_epsilon ()
DREAL get_epsilon ()
DREAL get_nu ()
DREAL get_C1 ()
DREAL get_C2 ()
int get_qpsize ()
int get_support_vector (INT idx)
DREAL get_alpha (INT idx)
bool set_support_vector (INT idx, INT val)
bool set_alpha (INT idx, DREAL val)
DREAL get_bias ()
void set_bias (DREAL bias)
int get_num_support_vectors ()
void set_alphas (DREAL *alphas, INT d)
void set_support_vectors (INT *svs, INT d)
void get_support_vectors (INT **svs, INT *num)
void get_alphas (DREAL **alphas, INT *d1)
bool create_new_model (INT num)
void set_shrinking_enabled (bool enable)
bool get_shrinking_enabled ()
void set_mkl_enabled (bool enable)
bool get_mkl_enabled ()
DREAL compute_objective ()
void set_objective (DREAL v)
DREAL get_objective ()
bool init_kernel_optimization ()
virtual CLabelsclassify (CLabels *lab=NULL)
virtual DREAL classify_example (INT num)
void set_precomputed_subkernels_enabled (bool flag)
void set_kernel (CKernel *k)
CKernelget_kernel ()
void set_batch_computation_enabled (bool enable)
bool get_batch_computation_enabled ()
void set_linadd_enabled (bool enable)
bool get_linadd_enabled ()
virtual bool train ()
virtual void set_labels (CLabels *lab)
virtual CLabelsget_labels ()
virtual DREAL get_label (INT i)
void set_max_train_time (DREAL t)
DREAL get_max_train_time ()
virtual EClassifierType get_classifier_type ()

Static Public Member Functions

static void * classify_example_helper (void *p)

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version

Protected Attributes

TModel svm_model
bool svm_loaded
DREAL weight_epsilon
DREAL epsilon
DREAL tube_epsilon
DREAL nu
DREAL C1
DREAL C2
DREAL C_mkl
DREAL objective
int qpsize
bool use_bias
bool use_shrinking
bool use_mkl
bool use_precomputed_subkernels
CKernelkernel
bool use_batch_computation
bool use_linadd
DREAL max_train_time
CLabelslabels

Classes

struct  TModel

Constructor & Destructor Documentation

CSVM::CSVM ( INT  num_sv = 0  ) 

Create an empty Support Vector Machine Object

Parameters:
num_sv with num_sv support vectors

Definition at line 33 of file SVM.cpp.

CSVM::CSVM ( DREAL  C,
CKernel k,
CLabels lab 
)

Create a Support Vector Machine Object from a trained SVM

Parameters:
C the C parameter
k the Kernel object
lab the Label object

Definition at line 39 of file SVM.cpp.

CSVM::~CSVM (  )  [virtual]

Definition at line 48 of file SVM.cpp.


Member Function Documentation

void CSVM::set_defaults ( INT  num_sv = 0  ) 

set default values for members a SVM object

Definition at line 56 of file SVM.cpp.

bool CSVM::load ( FILE *  svm_file  )  [virtual]

load a SVM from file

Parameters:
svm_file the file handle

Reimplemented from CClassifier.

Definition at line 87 of file SVM.cpp.

bool CSVM::save ( FILE *  svm_file  )  [virtual]

write a SVM to a file

Parameters:
svm_file the file handle

Reimplemented from CClassifier.

Definition at line 200 of file SVM.cpp.

void CSVM::set_nu ( DREAL  nue  ) 

set nu

Parameters:
nue new nu

Definition at line 79 of file SVM.h.

void CSVM::set_C ( DREAL  c1,
DREAL  c2 
)

set C

Parameters:
c1 new C1
c2 new C2

Definition at line 86 of file SVM.h.

void CSVM::set_weight_epsilon ( DREAL  eps  ) 

set epsilon for weights

Parameters:
eps new weight_epsilon

Definition at line 92 of file SVM.h.

void CSVM::set_epsilon ( DREAL  eps  ) 

set epsilon

Parameters:
eps new epsilon

Definition at line 98 of file SVM.h.

void CSVM::set_tube_epsilon ( DREAL  eps  ) 

set tube epsilon

Parameters:
eps new tube epsilon

Definition at line 104 of file SVM.h.

void CSVM::set_C_mkl ( DREAL  C  ) 

set C mkl

Parameters:
C new C_mkl

Definition at line 110 of file SVM.h.

void CSVM::set_qpsize ( INT  qps  ) 

set qpsize

Parameters:
qps new qpsize

Definition at line 116 of file SVM.h.

void CSVM::set_bias_enabled ( bool  enable_bias  ) 

set state of bias

Parameters:
enable_bias if bias shall be enabled

Definition at line 122 of file SVM.h.

bool CSVM::get_bias_enabled (  ) 

get state of bias

Returns:
state of bias

Definition at line 128 of file SVM.h.

DREAL CSVM::get_weight_epsilon (  ) 

get epsilon for weights

Returns:
epsilon for weights

Definition at line 134 of file SVM.h.

DREAL CSVM::get_epsilon (  ) 

get epsilon

Returns:
epsilon

Definition at line 140 of file SVM.h.

DREAL CSVM::get_nu (  ) 

get nu

Returns:
nu

Definition at line 146 of file SVM.h.

DREAL CSVM::get_C1 (  ) 

get C1

Returns:
C1

Definition at line 152 of file SVM.h.

DREAL CSVM::get_C2 (  ) 

get C2

Returns:
C2

Definition at line 158 of file SVM.h.

int CSVM::get_qpsize (  ) 

get qpsize

Returns:
qpsize

Definition at line 164 of file SVM.h.

int CSVM::get_support_vector ( INT  idx  ) 

get support vector at given index

Parameters:
idx index of support vector
Returns:
support vector

Definition at line 171 of file SVM.h.

DREAL CSVM::get_alpha ( INT  idx  ) 

get alpha at given index

Parameters:
idx index of alpha
Returns:
alpha

Definition at line 182 of file SVM.h.

bool CSVM::set_support_vector ( INT  idx,
INT  val 
)

set support vector at given index to given value

Parameters:
idx index of support vector
val new value of support vector
Returns:
if operation was successful

Definition at line 194 of file SVM.h.

bool CSVM::set_alpha ( INT  idx,
DREAL  val 
)

set alpha at given index to given value

Parameters:
idx index of alpha vector
val new value of alpha vector
Returns:
if operation was successful

Definition at line 210 of file SVM.h.

DREAL CSVM::get_bias (  ) 

get bias

Returns:
bias

Definition at line 224 of file SVM.h.

void CSVM::set_bias ( DREAL  bias  ) 

set bias to given value

Parameters:
bias new bias

Definition at line 233 of file SVM.h.

int CSVM::get_num_support_vectors (  ) 

get number of support vectors

Returns:
number of support vectors

Definition at line 242 of file SVM.h.

void CSVM::set_alphas ( DREAL alphas,
INT  d 
)

set alphas to given values

Parameters:
alphas array with all alphas to set
d number of alphas (== number of support vectors)

Definition at line 252 of file SVM.h.

void CSVM::set_support_vectors ( INT svs,
INT  d 
)

set support vectors to given values

Parameters:
svs array with all support vectors to set
d number of support vectors

Definition at line 266 of file SVM.h.

void CSVM::get_support_vectors ( INT **  svs,
INT num 
)

get all support vectors (swig compatible)

Parameters:
svs array to contain a copy of the support vectors
num number of support vectors in the array

Definition at line 280 of file SVM.h.

void CSVM::get_alphas ( DREAL **  alphas,
INT d1 
)

get all alphas (swig compatible)

Parameters:
alphas array to contain a copy of the alphas
d1 number of alphas in the array

Definition at line 301 of file SVM.h.

bool CSVM::create_new_model ( INT  num  ) 

create new model

Parameters:
num number of alphas and support vectors in new model

Definition at line 321 of file SVM.h.

void CSVM::set_shrinking_enabled ( bool  enable  ) 

set state of shrinking

Parameters:
enable if shrinking will be enabled

Definition at line 347 of file SVM.h.

bool CSVM::get_shrinking_enabled (  ) 

get state of shrinking

Returns:
if shrinking is enabled

Definition at line 356 of file SVM.h.

void CSVM::set_mkl_enabled ( bool  enable  ) 

set state of mkl

Parameters:
enable if mkl shall be enabled

Definition at line 365 of file SVM.h.

bool CSVM::get_mkl_enabled (  ) 

get state of mkl

Returns:
if mkl is enabled

Definition at line 374 of file SVM.h.

DREAL CSVM::compute_objective (  ) 

compute objective

Returns:
computed objective

Definition at line 412 of file SVM.cpp.

void CSVM::set_objective ( DREAL  v  ) 

set objective

Parameters:
v objective

Definition at line 389 of file SVM.h.

DREAL CSVM::get_objective (  ) 

get objective

Returns:
objective

Definition at line 398 of file SVM.h.

bool CSVM::init_kernel_optimization (  ) 

initialise kernel optimisation

Returns:
if operation was successful

Definition at line 220 of file SVM.cpp.

CLabels * CSVM::classify ( CLabels lab = NULL  )  [virtual]

classify SVM

Parameters:
lab classified labels
Returns:
classified labels

Reimplemented from CKernelMachine.

Reimplemented in CMultiClassSVM.

Definition at line 279 of file SVM.cpp.

DREAL CSVM::classify_example ( INT  num  )  [virtual]

classify one example

Parameters:
num which example to classify
Returns:
classified value

Reimplemented from CClassifier.

Reimplemented in CMultiClassSVM.

Definition at line 392 of file SVM.cpp.

void * CSVM::classify_example_helper ( void *  p  )  [static]

classify example helper, used in threads

Parameters:
p params of the thread
Returns:
nothing really

Definition at line 251 of file SVM.cpp.

void CSVM::set_precomputed_subkernels_enabled ( bool  flag  ) 

set state of precomputed subkernels

Parameters:
flag if precomputed subkernels shall be enabled

Definition at line 434 of file SVM.h.

void CKernelMachine::set_kernel ( CKernel k  )  [inherited]

set kernel

Parameters:
k kernel

Definition at line 51 of file KernelMachine.h.

CKernel* CKernelMachine::get_kernel (  )  [inherited]

get kernel

Returns:
kernel

Definition at line 62 of file KernelMachine.h.

void CKernelMachine::set_batch_computation_enabled ( bool  enable  )  [inherited]

set batch computation enabled

Parameters:
enable if batch computation shall be enabled

Definition at line 72 of file KernelMachine.h.

bool CKernelMachine::get_batch_computation_enabled (  )  [inherited]

check if batch computation is enabled

Returns:
if batch computation is enabled

Definition at line 81 of file KernelMachine.h.

void CKernelMachine::set_linadd_enabled ( bool  enable  )  [inherited]

set linadd enabled

Parameters:
enable if linadd shall be enabled

Definition at line 90 of file KernelMachine.h.

bool CKernelMachine::get_linadd_enabled (  )  [inherited]

check if linadd is enabled

Returns:
if linadd is enabled

Definition at line 99 of file KernelMachine.h.

virtual bool CClassifier::train (  )  [virtual, inherited]

train classifier

Returns:
whether training was successful

Reimplemented in CKernelPerceptron, CKNN, CPerceptron, CPluginEstimate, CGMNPSVM, CGNPPSVM, CGPBTSVM, CLibSVM, CLibSVMMultiClass, CLibSVMOneClass, CMPDSVM, CSubGradientSVM, CSVMLin, CSVMOcas, CSVMSGD, CWDSVMOcas, CHierarchical, CKMeans, and CLibSVR.

Definition at line 31 of file Classifier.h.

virtual void CClassifier::set_labels ( CLabels lab  )  [virtual, inherited]

set labels

Parameters:
lab labels

Definition at line 71 of file Classifier.h.

virtual CLabels* CClassifier::get_labels (  )  [virtual, inherited]

get labels

Returns:
labels

Definition at line 82 of file Classifier.h.

virtual DREAL CClassifier::get_label ( INT  i  )  [virtual, inherited]

get one specific label

Parameters:
i index of label to get
Returns:
value of label at index i

Definition at line 89 of file Classifier.h.

void CClassifier::set_max_train_time ( DREAL  t  )  [inherited]

set maximum training time

Parameters:
t maximimum training time

Definition at line 95 of file Classifier.h.

DREAL CClassifier::get_max_train_time (  )  [inherited]

get maximum training time

Returns:
maximum training time

Definition at line 101 of file Classifier.h.

virtual EClassifierType CClassifier::get_classifier_type (  )  [virtual, inherited]

get classifier type

Returns:
classifier type NONE

Reimplemented in CKernelPerceptron, CKNN, CPerceptron, CGMNPSVM, CGNPPSVM, CGPBTSVM, CLibSVM, CLibSVMMultiClass, CLibSVMOneClass, CMPDSVM, CSubGradientSVM, CSVMLin, CSVMOcas, CSVMSGD, CWDSVMOcas, CHierarchical, CKMeans, and CLibSVR.

Definition at line 107 of file Classifier.h.


Member Data Documentation

TModel CSVM::svm_model [protected]

SVM's model

Definition at line 455 of file SVM.h.

bool CSVM::svm_loaded [protected]

if SVM is loaded

Definition at line 457 of file SVM.h.

epsilon of weights

Definition at line 459 of file SVM.h.

DREAL CSVM::epsilon [protected]

epsilon

Definition at line 461 of file SVM.h.

tube epsilon

Definition at line 463 of file SVM.h.

DREAL CSVM::nu [protected]

nu

Definition at line 465 of file SVM.h.

DREAL CSVM::C1 [protected]

C1

Definition at line 467 of file SVM.h.

DREAL CSVM::C2 [protected]

C2

Definition at line 469 of file SVM.h.

DREAL CSVM::C_mkl [protected]

C_mkl

Definition at line 471 of file SVM.h.

DREAL CSVM::objective [protected]

objective

Definition at line 473 of file SVM.h.

int CSVM::qpsize [protected]

qpsize

Definition at line 475 of file SVM.h.

bool CSVM::use_bias [protected]

if bias shall be used

Definition at line 477 of file SVM.h.

bool CSVM::use_shrinking [protected]

if shrinking shall be used

Definition at line 479 of file SVM.h.

bool CSVM::use_mkl [protected]

if mkl shall be used

Definition at line 481 of file SVM.h.

if precomputed subkernels shall be used

Definition at line 483 of file SVM.h.

CKernel* CKernelMachine::kernel [protected, inherited]

kernel

Definition at line 113 of file KernelMachine.h.

bool CKernelMachine::use_batch_computation [protected, inherited]

if batch computation is enabled

Definition at line 115 of file KernelMachine.h.

bool CKernelMachine::use_linadd [protected, inherited]

if linadd is enabled

Definition at line 117 of file KernelMachine.h.

DREAL CClassifier::max_train_time [protected, inherited]

maximum training time

Definition at line 111 of file Classifier.h.

CLabels* CClassifier::labels [protected, inherited]

labels

Definition at line 114 of file Classifier.h.

CParallel CSGObject::parallel [static, inherited]

Definition at line 105 of file SGObject.h.

CIO CSGObject::io [static, inherited]

Definition at line 106 of file SGObject.h.

CVersion CSGObject::version [static, inherited]

Definition at line 107 of file SGObject.h.


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

SHOGUN Machine Learning Toolbox - Documentation