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 (int32_t num_sv=0)
 CSVM (float64_t C, CKernel *k, CLabels *lab)
virtual ~CSVM ()
void set_defaults (int32_t num_sv=0)
bool load (FILE *svm_file)
bool save (FILE *svm_file)
void set_nu (float64_t nue)
void set_C (float64_t c1, float64_t c2)
void set_weight_epsilon (float64_t eps)
void set_epsilon (float64_t eps)
void set_tube_epsilon (float64_t eps)
void set_C_mkl (float64_t C)
void set_mkl_norm (int32_t norm)
void set_qpsize (int32_t qps)
void set_bias_enabled (bool enable_bias)
bool get_bias_enabled ()
float64_t get_weight_epsilon ()
float64_t get_epsilon ()
float64_t get_nu ()
float64_t get_C1 ()
float64_t get_C2 ()
int32_t get_qpsize ()
int32_t get_support_vector (int32_t idx)
float64_t get_alpha (int32_t idx)
bool set_support_vector (int32_t idx, int32_t val)
bool set_alpha (int32_t idx, float64_t val)
float64_t get_bias ()
void set_bias (float64_t bias)
int32_t get_num_support_vectors ()
void set_alphas (float64_t *alphas, int32_t d)
void set_support_vectors (int32_t *svs, int32_t d)
void get_support_vectors (int32_t **svs, int32_t *num)
void get_alphas (float64_t **alphas, int32_t *d1)
bool create_new_model (int32_t num)
void set_shrinking_enabled (bool enable)
bool get_shrinking_enabled ()
void set_mkl_enabled (bool enable)
bool get_mkl_enabled ()
float64_t compute_objective ()
void set_objective (float64_t v)
float64_t get_objective ()
bool init_kernel_optimization ()
virtual CLabelsclassify (CLabels *lab=NULL)
virtual float64_t classify_example (int32_t num)

Static Public Member Functions

static void * classify_example_helper (void *p)

Protected Attributes

TModel svm_model
bool svm_loaded
float64_t weight_epsilon
float64_t epsilon
float64_t tube_epsilon
float64_t nu
float64_t C1
float64_t C2
int32_t mkl_norm
float64_t C_mkl
float64_t objective
int32_t qpsize
bool use_bias
bool use_shrinking
bool use_mkl

Classes

struct  TModel

Constructor & Destructor Documentation

CSVM::CSVM ( int32_t  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 ( float64_t  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 ( int32_t  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.

Reimplemented in CMultiClassSVM.

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.

Reimplemented in CMultiClassSVM.

Definition at line 200 of file SVM.cpp.

void CSVM::set_nu ( float64_t  nue  ) 

set nu

Parameters:
nue new nu

Definition at line 79 of file SVM.h.

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

set C

Parameters:
c1 new C constant for negatively labelled examples
c2 new C constant for positively labelled examples
Note that not all SVMs support this (however at least CLibSVM and CSVMLight do)

Definition at line 89 of file SVM.h.

void CSVM::set_weight_epsilon ( float64_t  eps  ) 

set epsilon for weights

Parameters:
eps new weight_epsilon

Definition at line 95 of file SVM.h.

void CSVM::set_epsilon ( float64_t  eps  ) 

set epsilon

Parameters:
eps new epsilon

Definition at line 101 of file SVM.h.

void CSVM::set_tube_epsilon ( float64_t  eps  ) 

set tube epsilon

Parameters:
eps new tube epsilon

Definition at line 107 of file SVM.h.

void CSVM::set_C_mkl ( float64_t  C  ) 

set C mkl

Parameters:
C new C_mkl

Definition at line 113 of file SVM.h.

void CSVM::set_mkl_norm ( int32_t  norm  ) 

set mkl norm

Parameters:
norm new mkl norm (1 or 2)

Definition at line 119 of file SVM.h.

void CSVM::set_qpsize ( int32_t  qps  ) 

set qpsize

Parameters:
qps new qpsize

Definition at line 130 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 136 of file SVM.h.

bool CSVM::get_bias_enabled (  ) 

get state of bias

Returns:
state of bias

Definition at line 142 of file SVM.h.

float64_t CSVM::get_weight_epsilon (  ) 

get epsilon for weights

Returns:
epsilon for weights

Definition at line 148 of file SVM.h.

float64_t CSVM::get_epsilon (  ) 

get epsilon

Returns:
epsilon

Definition at line 154 of file SVM.h.

float64_t CSVM::get_nu (  ) 

get nu

Returns:
nu

Definition at line 160 of file SVM.h.

float64_t CSVM::get_C1 (  ) 

get C1

Returns:
C1

Definition at line 166 of file SVM.h.

float64_t CSVM::get_C2 (  ) 

get C2

Returns:
C2

Definition at line 172 of file SVM.h.

int32_t CSVM::get_qpsize (  ) 

get qpsize

Returns:
qpsize

Definition at line 178 of file SVM.h.

int32_t CSVM::get_support_vector ( int32_t  idx  ) 

get support vector at given index

Parameters:
idx index of support vector
Returns:
support vector

Definition at line 185 of file SVM.h.

float64_t CSVM::get_alpha ( int32_t  idx  ) 

get alpha at given index

Parameters:
idx index of alpha
Returns:
alpha

Definition at line 196 of file SVM.h.

bool CSVM::set_support_vector ( int32_t  idx,
int32_t  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 208 of file SVM.h.

bool CSVM::set_alpha ( int32_t  idx,
float64_t  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 224 of file SVM.h.

float64_t CSVM::get_bias (  ) 

get bias

Returns:
bias

Definition at line 238 of file SVM.h.

void CSVM::set_bias ( float64_t  bias  ) 

set bias to given value

Parameters:
bias new bias

Definition at line 247 of file SVM.h.

int32_t CSVM::get_num_support_vectors (  ) 

get number of support vectors

Returns:
number of support vectors

Definition at line 256 of file SVM.h.

void CSVM::set_alphas ( float64_t alphas,
int32_t  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 266 of file SVM.h.

void CSVM::set_support_vectors ( int32_t *  svs,
int32_t  d 
)

set support vectors to given values

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

Definition at line 280 of file SVM.h.

void CSVM::get_support_vectors ( int32_t **  svs,
int32_t *  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 294 of file SVM.h.

void CSVM::get_alphas ( float64_t **  alphas,
int32_t *  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 315 of file SVM.h.

bool CSVM::create_new_model ( int32_t  num  ) 

create new model

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

Definition at line 335 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 361 of file SVM.h.

bool CSVM::get_shrinking_enabled (  ) 

get state of shrinking

Returns:
if shrinking is enabled

Definition at line 370 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 379 of file SVM.h.

bool CSVM::get_mkl_enabled (  ) 

get state of mkl

Returns:
if mkl is enabled

Definition at line 388 of file SVM.h.

float64_t CSVM::compute_objective (  ) 

compute objective

Returns:
computed objective

Definition at line 415 of file SVM.cpp.

void CSVM::set_objective ( float64_t  v  ) 

set objective

Parameters:
v objective

Definition at line 403 of file SVM.h.

float64_t CSVM::get_objective (  ) 

get objective

Returns:
objective

Definition at line 412 of file SVM.h.

bool CSVM::init_kernel_optimization (  ) 

initialise kernel optimisation

Returns:
if operation was successful

Definition at line 223 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 282 of file SVM.cpp.

float64_t CSVM::classify_example ( int32_t  num  )  [virtual]

classify one example

Parameters:
num which example to classify
Returns:
classified value

Reimplemented from CClassifier.

Reimplemented in CMultiClassSVM.

Definition at line 395 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 254 of file SVM.cpp.


Member Data Documentation

TModel CSVM::svm_model [protected]

SVM's model

Definition at line 460 of file SVM.h.

bool CSVM::svm_loaded [protected]

if SVM is loaded

Definition at line 462 of file SVM.h.

epsilon for multiple kernel learning

Definition at line 464 of file SVM.h.

float64_t CSVM::epsilon [protected]

epsilon

Definition at line 466 of file SVM.h.

tube epsilon for support vector regression

Definition at line 468 of file SVM.h.

float64_t CSVM::nu [protected]

nu

Definition at line 470 of file SVM.h.

float64_t CSVM::C1 [protected]

C1 regularization const

Definition at line 472 of file SVM.h.

float64_t CSVM::C2 [protected]

C2

Definition at line 474 of file SVM.h.

int32_t CSVM::mkl_norm [protected]

norm used in mkl, can be 1 or 2

Definition at line 476 of file SVM.h.

float64_t CSVM::C_mkl [protected]

C_mkl

Definition at line 478 of file SVM.h.

objective

Definition at line 480 of file SVM.h.

int32_t CSVM::qpsize [protected]

qpsize

Definition at line 482 of file SVM.h.

bool CSVM::use_bias [protected]

if bias shall be used

Definition at line 484 of file SVM.h.

bool CSVM::use_shrinking [protected]

if shrinking shall be used

Definition at line 486 of file SVM.h.

bool CSVM::use_mkl [protected]

if mkl shall be used

Definition at line 488 of file SVM.h.


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

SHOGUN Machine Learning Toolbox - Documentation