Public Member Functions | Protected Member Functions | Protected Attributes
clsfy_rbf_svm Class Reference

A Support Vector Machine Binary Classifier. More...

#include <clsfy_rbf_svm.h>

Inheritance diagram for clsfy_rbf_svm:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 clsfy_rbf_svm ()
 Dflt constructor.
virtual ~clsfy_rbf_svm ()
 Destructor.
virtual unsigned classify (const vnl_vector< double > &input) const
 Classify the input vector.
virtual void class_probabilities (vcl_vector< double > &outputs, const vnl_vector< double > &input) const
 Return the probability the input being in each class.
virtual double log_l (const vnl_vector< double > &input) const
 Log likelihood of being in class (binary classifiers only).
virtual void set (const vcl_vector< vnl_vector< double > > &supportVectors, const vcl_vector< double > &lagrangianAlphas, const vcl_vector< unsigned > &labels, double RBFWidth, double bias)
 Set the internal values defining the classifier.
double rbf_width () const
 The 1st standard deviation width of the RBF kernel.
unsigned n_support_vectors () const
 The number of support vectors.
double kernel (const vnl_vector< double > &v1, const vnl_vector< double > &v2) const
 The kernel function.
double bias () const
 The SVM function bias.
const vcl_vector< double > & lagrangians () const
 The Lagrange multipliers.
const vcl_vector< vnl_vector
< double > > & 
support_vectors () const
 The support vectors.
virtual unsigned n_classes () const
 The number of possible output classes.
virtual unsigned n_dims () const
 The dimensionality of input vectors.
short version_no () const
 Return the class's IO version number.
virtual vcl_string is_a () const
 Name of the class.
virtual bool is_class (vcl_string const &s) const
 Name of the class.
virtual clsfy_classifier_baseclone () const
 Create a copy on the heap and return base class pointer.
virtual void print_summary (vcl_ostream &os) const
 Print class to os.
virtual void b_write (vsl_b_ostream &bfs) const
 Save class to binary file stream.
virtual void b_read (vsl_b_istream &bfs)
 Load class from binary file stream.
virtual void classify_many (vcl_vector< unsigned > &outputs, mbl_data_wrapper< vnl_vector< double > > &inputs) const
 Classify many input vectors.

Protected Member Functions

void calculate_targets ()
 Set the private target member values to the correct value.
double localEuclideanDistanceSq (const vnl_vector< double > &a, const vnl_vector< double > &b) const
 Calculate the contribution of a single support vector to the classifier;.

Protected Attributes

double upper_target_
 the starting upper bound.
double lower_target_
 the starting lower bound.
vcl_vector< vnl_vector< double > > supports_
 The support vectors.
vcl_vector< double > lagrangians_
 The Lagrangian multipliers.
double bias_
 The offset bias.
double gamma_

Detailed Description

A Support Vector Machine Binary Classifier.

Definition at line 21 of file clsfy_rbf_svm.h.


Constructor & Destructor Documentation

clsfy_rbf_svm::clsfy_rbf_svm ( )

Dflt constructor.

Definition at line 20 of file clsfy_rbf_svm.cxx.

clsfy_rbf_svm::~clsfy_rbf_svm ( ) [virtual]

Destructor.

Definition at line 26 of file clsfy_rbf_svm.cxx.


Member Function Documentation

void clsfy_rbf_svm::b_read ( vsl_b_istream bfs) [virtual]

Load class from binary file stream.

Implements clsfy_classifier_base.

Definition at line 192 of file clsfy_rbf_svm.cxx.

void clsfy_rbf_svm::b_write ( vsl_b_ostream bfs) const [virtual]

Save class to binary file stream.

Implements clsfy_classifier_base.

Definition at line 181 of file clsfy_rbf_svm.cxx.

double clsfy_rbf_svm::bias ( ) const [inline]

The SVM function bias.

Definition at line 91 of file clsfy_rbf_svm.h.

void clsfy_rbf_svm::calculate_targets ( ) [protected]

Set the private target member values to the correct value.

Definition at line 103 of file clsfy_rbf_svm.cxx.

void clsfy_rbf_svm::class_probabilities ( vcl_vector< double > &  outputs,
const vnl_vector< double > &  input 
) const [virtual]

Return the probability the input being in each class.

output(i) i<<nClasses, contains the probability that the input is in class i; This are not strict probability values, since SVMs do not give Bayesian outputs. However their properties fit the requirements of a probability.

Implements clsfy_classifier_base.

Definition at line 88 of file clsfy_rbf_svm.cxx.

unsigned clsfy_rbf_svm::classify ( const vnl_vector< double > &  input) const [virtual]

Classify the input vector.

returns 0 to indicate out of (or negative) class and one to indicate in class (or positive.)

Returns 0 to indicate out of (or negative) class and one to indicate in class (or positive.)

Reimplemented from clsfy_classifier_base.

Definition at line 44 of file clsfy_rbf_svm.cxx.

void clsfy_classifier_base::classify_many ( vcl_vector< unsigned > &  outputs,
mbl_data_wrapper< vnl_vector< double > > &  inputs 
) const [virtual, inherited]

Classify many input vectors.

Definition at line 55 of file clsfy_classifier_base.cxx.

clsfy_classifier_base * clsfy_rbf_svm::clone ( ) const [virtual]

Create a copy on the heap and return base class pointer.

Implements clsfy_classifier_base.

Definition at line 164 of file clsfy_rbf_svm.cxx.

vcl_string clsfy_rbf_svm::is_a ( ) const [virtual]

Name of the class.

Reimplemented from clsfy_classifier_base.

Definition at line 143 of file clsfy_rbf_svm.cxx.

bool clsfy_rbf_svm::is_class ( vcl_string const &  s) const [virtual]

Name of the class.

Reimplemented from clsfy_classifier_base.

Definition at line 150 of file clsfy_rbf_svm.cxx.

double clsfy_rbf_svm::kernel ( const vnl_vector< double > &  v1,
const vnl_vector< double > &  v2 
) const

The kernel function.

Uses the SVM's current value of RBFWidth.

Definition at line 33 of file clsfy_rbf_svm.cxx.

const vcl_vector<double>& clsfy_rbf_svm::lagrangians ( ) const [inline]

The Lagrange multipliers.

The values corresponding to negative training vectors are pre-multiplied by -1. The array ordering corresponds to supportVectors()

Definition at line 96 of file clsfy_rbf_svm.h.

double clsfy_rbf_svm::localEuclideanDistanceSq ( const vnl_vector< double > &  a,
const vnl_vector< double > &  b 
) const [inline, protected]

Calculate the contribution of a single support vector to the classifier;.

This local version is used so that the number of calls can be tested.

Definition at line 136 of file clsfy_rbf_svm.h.

double clsfy_rbf_svm::log_l ( const vnl_vector< double > &  input) const [virtual]

Log likelihood of being in class (binary classifiers only).

class probability = vcl_exp(logL) / (1+vcl_exp(logL)

class probability = vcl_exp(logL) / (1+vcl_exp(logL)) This is not a strict log likelihood value, since SVMs do not give Bayesian outputs. However its properties fit the requirements of a log likelihood value.

Implements clsfy_classifier_base.

Definition at line 72 of file clsfy_rbf_svm.cxx.

virtual unsigned clsfy_rbf_svm::n_classes ( ) const [inline, virtual]

The number of possible output classes.

Implements clsfy_classifier_base.

Definition at line 104 of file clsfy_rbf_svm.h.

virtual unsigned clsfy_rbf_svm::n_dims ( ) const [inline, virtual]

The dimensionality of input vectors.

Implements clsfy_classifier_base.

Definition at line 107 of file clsfy_rbf_svm.h.

unsigned clsfy_rbf_svm::n_support_vectors ( ) const [inline]

The number of support vectors.

Definition at line 84 of file clsfy_rbf_svm.h.

void clsfy_rbf_svm::print_summary ( vcl_ostream &  os) const [virtual]

Print class to os.

Implements clsfy_classifier_base.

Definition at line 171 of file clsfy_rbf_svm.cxx.

double clsfy_rbf_svm::rbf_width ( ) const [inline]

The 1st standard deviation width of the RBF kernel.

Really this could be better named as the RBF radius.

Definition at line 81 of file clsfy_rbf_svm.h.

void clsfy_rbf_svm::set ( const vcl_vector< vnl_vector< double > > &  supportVectors,
const vcl_vector< double > &  lagrangianAlphas,
const vcl_vector< unsigned > &  labels,
double  RBFWidth,
double  bias 
) [virtual]

Set the internal values defining the classifier.

Parameters:
supportVectors
lagrangianAlphas
labelsThese should be 0 or 1.
RBFWidth
bias

Definition at line 120 of file clsfy_rbf_svm.cxx.

const vcl_vector<vnl_vector<double> >& clsfy_rbf_svm::support_vectors ( ) const [inline]

The support vectors.

The array ordering corresponds to lagrangians()

Definition at line 100 of file clsfy_rbf_svm.h.

short clsfy_rbf_svm::version_no ( ) const

Return the class's IO version number.

Definition at line 157 of file clsfy_rbf_svm.cxx.


Member Data Documentation

double clsfy_rbf_svm::bias_ [protected]

The offset bias.

Definition at line 39 of file clsfy_rbf_svm.h.

double clsfy_rbf_svm::gamma_ [protected]

-1/(2 * sigma*sigma), where sigma = RBF kernel width.

Definition at line 42 of file clsfy_rbf_svm.h.

vcl_vector<double> clsfy_rbf_svm::lagrangians_ [protected]

The Lagrangian multipliers.

The values have been pre-multiplied by the +/-1.0 depending on the support target.

Definition at line 36 of file clsfy_rbf_svm.h.

double clsfy_rbf_svm::lower_target_ [protected]

the starting lower bound.

If the function sum falls below this value, the decision will definitely be 0.

Definition at line 29 of file clsfy_rbf_svm.h.

vcl_vector<vnl_vector<double> > clsfy_rbf_svm::supports_ [protected]

The support vectors.

Definition at line 32 of file clsfy_rbf_svm.h.

double clsfy_rbf_svm::upper_target_ [protected]

the starting upper bound.

If the function sum exceeds this value, the decision will definitely be 1.

Definition at line 26 of file clsfy_rbf_svm.h.


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