SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
CSVM Class Reference

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 46 of file SVM.h.

Inheritance diagram for CSVM:
Inheritance graph
[legend]

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)
virtual SGVector< float64_tget_linear_term ()
virtual void set_linear_term (SGVector< float64_t > linear_term)
bool load (FILE *svm_file)
bool save (FILE *svm_file)
void set_nu (float64_t nue)
void set_C (float64_t c_neg, float64_t c_pos)
void set_epsilon (float64_t eps)
void set_tube_epsilon (float64_t eps)
float64_t get_tube_epsilon ()
void set_qpsize (int32_t qps)
float64_t get_epsilon ()
float64_t get_nu ()
float64_t get_C1 ()
float64_t get_C2 ()
int32_t get_qpsize ()
void set_shrinking_enabled (bool enable)
bool get_shrinking_enabled ()
float64_t compute_svm_dual_objective ()
float64_t compute_svm_primal_objective ()
void set_objective (float64_t v)
float64_t get_objective ()
void set_callback_function (CMKL *m, bool(*cb)(CMKL *mkl, const float64_t *sumw, const float64_t suma))
virtual const char * get_name () const
- Public Member Functions inherited from CKernelMachine
 CKernelMachine ()
virtual ~CKernelMachine ()
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 ()
void set_bias_enabled (bool enable_bias)
bool get_bias_enabled ()
float64_t get_bias ()
void set_bias (float64_t bias)
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)
int32_t get_num_support_vectors ()
void set_alphas (SGVector< float64_t > alphas)
void set_support_vectors (SGVector< int32_t > svs)
SGVector< int32_t > get_support_vectors ()
SGVector< float64_tget_alphas ()
bool create_new_model (int32_t num)
bool init_kernel_optimization ()
virtual CLabelsapply ()
virtual CLabelsapply (CFeatures *data)
virtual float64_t apply (int32_t num)
- Public Member Functions inherited from CMachine
 CMachine ()
virtual ~CMachine ()
virtual bool train (CFeatures *data=NULL)
virtual void set_labels (CLabels *lab)
virtual CLabelsget_labels ()
virtual float64_t get_label (int32_t i)
void set_max_train_time (float64_t t)
float64_t get_max_train_time ()
virtual EClassifierType get_classifier_type ()
void set_solver_type (ESolverType st)
ESolverType get_solver_type ()
virtual void set_store_model_features (bool store_model)
- Public Member Functions inherited from CSGObject
 CSGObject ()
 CSGObject (const CSGObject &orig)
virtual ~CSGObject ()
virtual bool is_generic (EPrimitiveType *generic) const
template<class T >
void set_generic ()
void unset_generic ()
virtual void print_serializable (const char *prefix="")
virtual bool save_serializable (CSerializableFile *file, const char *prefix="")
virtual bool load_serializable (CSerializableFile *file, const char *prefix="")
void set_global_io (SGIO *io)
SGIOget_global_io ()
void set_global_parallel (Parallel *parallel)
Parallelget_global_parallel ()
void set_global_version (Version *version)
Versionget_global_version ()
SGVector< char * > get_modelsel_names ()
char * get_modsel_param_descr (const char *param_name)
index_t get_modsel_param_index (const char *param_name)

Protected Member Functions

virtual float64_tget_linear_term_array ()
- Protected Member Functions inherited from CKernelMachine
virtual void store_model_features ()
- Protected Member Functions inherited from CMachine
virtual bool train_machine (CFeatures *data=NULL)
- Protected Member Functions inherited from CSGObject
virtual void load_serializable_pre () throw (ShogunException)
virtual void load_serializable_post () throw (ShogunException)
virtual void save_serializable_pre () throw (ShogunException)
virtual void save_serializable_post () throw (ShogunException)

Protected Attributes

SGVector< float64_tm_linear_term
bool svm_loaded
float64_t epsilon
float64_t tube_epsilon
float64_t nu
float64_t C1
float64_t C2
float64_t objective
int32_t qpsize
bool use_shrinking
bool(* callback )(CMKL *mkl, const float64_t *sumw, const float64_t suma)
CMKLmkl
- Protected Attributes inherited from CKernelMachine
CKernelkernel
bool use_batch_computation
bool use_linadd
bool use_bias
float64_t m_bias
SGVector< float64_tm_alpha
SGVector< int32_t > m_svs
- Protected Attributes inherited from CMachine
float64_t max_train_time
CLabelslabels
ESolverType solver_type
bool m_store_model_features

Additional Inherited Members

- Static Public Member Functions inherited from CKernelMachine
static void * apply_helper (void *p)
- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters

Constructor & Destructor Documentation

CSVM ( int32_t  num_sv = 0)

Create an empty Support Vector Machine Object

Parameters
num_svwith num_sv support vectors

Definition at line 27 of file SVM.cpp.

CSVM ( float64_t  C,
CKernel k,
CLabels lab 
)

Create a Support Vector Machine Object from a trained SVM

Parameters
Cthe C parameter
kthe Kernel object
labthe Label object

Definition at line 33 of file SVM.cpp.

~CSVM ( )
virtual

Definition at line 42 of file SVM.cpp.

Member Function Documentation

float64_t compute_svm_dual_objective ( )

compute svm dual objective

Returns
computed dual objective

Definition at line 242 of file SVM.cpp.

float64_t compute_svm_primal_objective ( )

compute svm primal objective

Returns
computed svm primal objective

Definition at line 267 of file SVM.cpp.

float64_t get_C1 ( )

get C1

Returns
C1

Definition at line 153 of file SVM.h.

float64_t get_C2 ( )

get C2

Returns
C2

Definition at line 159 of file SVM.h.

float64_t get_epsilon ( )

get epsilon

Returns
epsilon

Definition at line 141 of file SVM.h.

SGVector< float64_t > get_linear_term ( )
virtual

get linear term

Returns
the linear term

Definition at line 337 of file SVM.cpp.

float64_t * get_linear_term_array ( )
protectedvirtual

get linear term copy as dynamic array

Returns
linear term copied to a dynamic array

Definition at line 302 of file SVM.cpp.

virtual const char* get_name ( ) const
virtual
Returns
object name

Reimplemented from CKernelMachine.

Reimplemented in CLaRank, CMKL, CScatterSVM, CLibSVR, CGMNPSVM, CLibSVM, CGPBTSVM, CLibSVMMultiClass, CLibSVMOneClass, CGNPPSVM, and CMPDSVM.

Definition at line 226 of file SVM.h.

float64_t get_nu ( )

get nu

Returns
nu

Definition at line 147 of file SVM.h.

float64_t get_objective ( )

get objective

Returns
objective

Definition at line 210 of file SVM.h.

int32_t get_qpsize ( )

get qpsize

Returns
qpsize

Definition at line 165 of file SVM.h.

bool get_shrinking_enabled ( )

get state of shrinking

Returns
if shrinking is enabled

Definition at line 180 of file SVM.h.

float64_t get_tube_epsilon ( )

get tube epsilon

Returns
tube epsilon

Definition at line 129 of file SVM.h.

bool load ( FILE *  svm_file)
virtual

load a SVM from file

Parameters
svm_filethe file handle

Reimplemented from CMachine.

Reimplemented in CMultiClassSVM.

Definition at line 90 of file SVM.cpp.

bool save ( FILE *  svm_file)
virtual

write a SVM to a file

Parameters
svm_filethe file handle

Reimplemented from CMachine.

Reimplemented in CMultiClassSVM.

Definition at line 206 of file SVM.cpp.

void set_C ( float64_t  c_neg,
float64_t  c_pos 
)

set C

Parameters
c_negnew C constant for negatively labeled examples
c_posnew C constant for positively labeled examples

Note that not all SVMs support this (however at least CLibSVM and CSVMLight do)

Definition at line 110 of file SVM.h.

void set_callback_function ( CMKL m,
bool(*)(CMKL *mkl, const float64_t *sumw, const float64_t suma)  cb 
)

set callback function svm optimizers may call when they have a new (small) set of alphas

Parameters
mpointer to mkl object
cbcallback function

Definition at line 232 of file SVM.cpp.

void set_defaults ( int32_t  num_sv = 0)

set default values for members a SVM object

Definition at line 48 of file SVM.cpp.

void set_epsilon ( float64_t  eps)

set epsilon

Parameters
epsnew epsilon

Definition at line 117 of file SVM.h.

void set_linear_term ( SGVector< float64_t linear_term)
virtual

set linear term of the QP

Parameters
linear_termthe linear term

Definition at line 314 of file SVM.cpp.

void set_nu ( float64_t  nue)

set nu

Parameters
nuenew nu

Definition at line 99 of file SVM.h.

void set_objective ( float64_t  v)

set objective

Parameters
vobjective

Definition at line 201 of file SVM.h.

void set_qpsize ( int32_t  qps)

set qpsize

Parameters
qpsnew qpsize

Definition at line 135 of file SVM.h.

void set_shrinking_enabled ( bool  enable)

set state of shrinking

Parameters
enableif shrinking will be enabled

Definition at line 171 of file SVM.h.

void set_tube_epsilon ( float64_t  eps)

set tube epsilon

Parameters
epsnew tube epsilon

Definition at line 123 of file SVM.h.

Member Data Documentation

float64_t C1
protected

C1 regularization const

Definition at line 249 of file SVM.h.

float64_t C2
protected

C2

Definition at line 251 of file SVM.h.

bool(* callback)(CMKL *mkl, const float64_t *sumw, const float64_t suma)
protected

callback function svm optimizers may call when they have a new (small) set of alphas

Definition at line 261 of file SVM.h.

float64_t epsilon
protected

epsilon

Definition at line 243 of file SVM.h.

SGVector<float64_t> m_linear_term
protected

linear term in qp

Definition at line 238 of file SVM.h.

CMKL* mkl
protected

mkl object that svm optimizers need to pass when calling the callback function

Definition at line 264 of file SVM.h.

float64_t nu
protected

nu

Definition at line 247 of file SVM.h.

float64_t objective
protected

objective

Definition at line 253 of file SVM.h.

int32_t qpsize
protected

qpsize

Definition at line 255 of file SVM.h.

bool svm_loaded
protected

if SVM is loaded

Definition at line 241 of file SVM.h.

float64_t tube_epsilon
protected

tube epsilon for support vector regression

Definition at line 245 of file SVM.h.

bool use_shrinking
protected

if shrinking shall be used

Definition at line 257 of file SVM.h.


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

SHOGUN Machine Learning Toolbox - Documentation