Click here to Skip to main content
6,822,613 members and growing! (15,481 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Neural Networks     Intermediate License: The GNU General Public License (GPL)

Support Vector Machine Classifier

By Chesnokov Yuriy

SVM classification class with SSE optimization support
C++ (VC6, VC7, VC7.1, VC8.0), C, Windows, Dev
Revision:2 (See All)
Posted:13 Apr 2008
Views:17,934
Bookmarked:26 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
10 votes for this article.
Popularity: 3.64 Rating: 3.64 out of 5
2 votes, 20.0%
1

2
1 vote, 10.0%
3

4
7 votes, 70.0%
5

Introduction

Support vector machine (SVM) is a non-linear classifier which is often reported as producing superior classification results compared to other methods. The idea behind the method is to non-linearly map the input data to some high dimensional space, where the data can be linearly separated, thus providing great classification (or regression) performance. One of the bottlenecks of the SVM is the large number of support vectors used from the training set to perform classification (regression) tasks. In my code, I use SSE optimization to increase performance.

Background (optional)

www.kernel-machines.org is a great source for SVM information.

Using the Code

In SVM class, I use my 2D SSE optimized vector code for faster computation. The SVMachine class contains the following functions you need to use:

  • SVMachine::SVMachine(const wchar_t* fname); ctor
  • int SVMachine::status() const; status after ctor (0 upon success and negative in case of errors)
  • unsigned int SVMachine::dimension() const; the dimensionality of the SVM
  • int SVMachine::classify(const float* x, double& y) const; to classify unknown vector x

ctor reads SVM configuration from file having the following text format:

input vector dimensionality
number of support vectors
kernel type [kernel parameter]

bias

weight
1st support vector    

weight
2nd support vector

...

For example, polynomial kernel SVM for iris data set to classify setosa from virgi consisted from 4 support vectors is presented below:

4
4
polynomial 3

1.1854890124462447

7.792329562624775e-012
51
33
17
5
 
9.9563612529691003e-012
48
34
19
2
 
1.0631195782759572e-011
51
38
19
4
 
-2.8372847134273557e-011
49
25
45
17

The SVM decision function is presented by the following formula:

SVM decision function

Where x is the input vector, alpha and y are the weights of the support vectors, having y as positive or negative class mark (+1 or -1) and b is the bias. From the iris SVM file, we can see that there are 4 four dimensional support vectors (3 first from positive class being setosa samples and the last one from negative class pertaining to virgi), the kernel is the polynomial one with 3 as the parameter, the bias is equal to 1.1854890124462447.

In my class, I use 3 kernels.

  1. linear:

    linear kernel

  2. rbf:

    RBF kernel

  3. polynomial:

    polynomial kernel

    Where param is the [kernel parameter] in the SVM file.

Typically a grid search is used to select best classification (regression) results by varying alpha and param over some range. In my iris SVM, the alphas are equal to 1 and param is the degree of polynomial.

To classify unknown vector sample x as belonging to positive or negative class, use SVMachine::classify() function. It returns +1 or -1 as the result of classification and provides to y the result of sum from the SVM decision formula.

Points of Interest

Add other kernels.

History

  • 14th April, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPL)

About the Author

Chesnokov Yuriy


Member
Former Cambridge University post-doc (http://www-ucc.ch.cam.ac.uk/research/yc274-research.html) currently lives in Krasnodar, Russia and doing some contract research for third parties. Research intrests in digital signal processing in medicine, image and video processing, pattern recognition, AI methods, computer vision. You may approach me for the code/research development in the above areas chesnokov.yuriy@gmail.com.

Publications:

Complexity and spectral analysis of the heart rate variability dynamics for distant prediction of paroxysmal atrial fibrillation with artificial intelligence methods. Artificial Intelligence in Medicine. 2008. V43/2. PP. 151-165 (http://dx.doi.org/10.1016/j.artmed.2008.03.009)

Face Detection C++ Library with Skin and Motion Analysis. Biometrics AIA 2007 TTS. 22 November 2007, Moscow, Russia. (http://www.dancom.ru/rus/AIA/2007TTS/ProgramAIA2007TTS.html)

Screening Patients with Paroxysmal Atrial Fibrillation (PAF) from Non-PAF Heart Rhythm Using HRV Data Analysis. Computers in Cardiology 2007. V. 34. PP. 459–463 (http://www.cinc.org/Proceedings/2007/pdf/0459.pdf)

Distant Prediction of Paroxysmal Atrial Fibrillation Using HRV Data Analysis. Computers in Cardiology 2007. V. 34. PP. 455-459 (http://www.cinc.org/Proceedings/2007/pdf/0455.pdf)

Individually Adaptable Automatic QT Detector. Computers in Cardiology 2006. V. 33. PP. 337-341 http://www.cinc.org/Proceedings/2006/pdf/0337.pdf)


Past/recent outsourcing code/research:

www.bitcycle.com - AI consulting
www.cit.ie - augmented reality C++
www.apniecare.com - ECG processing C++/C#
www.ayonix.com - face recognition C/C++/C#/ASP.NET/MATLAB
confidential company in Australia - video capture C#/DirectShow
www.system7.co.uk - CBIR C#/ASP.NET (cbir.system7.com)
confidential enterprise in UK - pedestrian detection C++/CLI
www.trulyintelligent.com - AI consulting
www.devline.ru - video codecs C++
ecotec.kuban.ru - embedded programming in C/C++
Occupation: Software Developer (Junior)
Company: Ayonix (face recognition)
Location: Russian Federation Russian Federation

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
Generalonevsrest svm Pinmembererolco14:41 11 Dec '09  
Generalonly classifier PinmemberLalitM200919:24 17 May '09  
Generalhow to train the SVM Pinmemberhuashanyjj23:46 1 Apr '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 13 Apr 2008
Editor: Deeksha Shenoy
Copyright 2008 by Chesnokov Yuriy
Everything else Copyright © CodeProject, 1999-2010
Web21 | Advertise on the Code Project