Public Member Functions | Protected Attributes

CLinearClassifier Class Reference


Detailed Description

Class LinearClassifier is a generic interface for all kinds of linear classifiers.

A linear classifier computes

\[ f({\bf x})= {\bf w} \cdot {\bf x} + b \]

where ${\bf w}$ are the weights assigned to each feature in training and $b$ the bias.

To implement a linear classifier all that is required is to define the train() function that delivers ${\bf w}$ above.

Note that this framework works with linear classifiers of arbitraty feature type, e.g. dense and sparse and even string based features. This is implemented by using CDotFeatures that may provide a mapping function $\Phi({\bf x})\mapsto {\cal R^D}$ encapsulating all the required operations (like the dot product). The decision function is thus

\[ f({\bf x})= {\bf w} \cdot \Phi({\bf x}) + b. \]

The following linear classifiers are implemented

See also:
CDotFeatures

Definition at line 60 of file LinearClassifier.h.

Inheritance diagram for CLinearClassifier:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CLinearClassifier ()
virtual ~CLinearClassifier ()
virtual float64_t classify_example (int32_t vec_idx)
 get output for example "vec_idx"
void get_w (float64_t *&dst_w, int32_t &dst_dims)
void get_w (float64_t **dst_w, int32_t *dst_dims)
void set_w (float64_t *src_w, int32_t src_w_dim)
void set_bias (float64_t b)
float64_t get_bias ()
virtual bool load (FILE *srcfile)
virtual bool save (FILE *dstfile)
virtual void set_features (CDotFeatures *feat)
virtual CLabelsclassify ()
virtual CLabelsclassify (CFeatures *data)
virtual CDotFeaturesget_features ()
virtual const char * get_name (void) const

Protected Attributes

int32_t w_dim
float64_tw
float64_t bias
CDotFeaturesfeatures

Constructor & Destructor Documentation

default constructor

Definition at line 16 of file LinearClassifier.cpp.

~CLinearClassifier (  )  [virtual]

Definition at line 26 of file LinearClassifier.cpp.


Member Function Documentation

CLabels * classify (  )  [virtual]

classify all examples

Returns:
resulting labels

Implements CClassifier.

Definition at line 46 of file LinearClassifier.cpp.

CLabels * classify ( CFeatures data  )  [virtual]

classify objects

Parameters:
data (test)data to be classified
Returns:
classified labels

Implements CClassifier.

Definition at line 68 of file LinearClassifier.cpp.

virtual float64_t classify_example ( int32_t  vec_idx  )  [virtual]

get output for example "vec_idx"

Reimplemented from CClassifier.

Definition at line 68 of file LinearClassifier.h.

float64_t get_bias (  ) 

get bias

Returns:
bias

Definition at line 126 of file LinearClassifier.h.

virtual CDotFeatures* get_features (  )  [virtual]

get features

Returns:
features

Definition at line 173 of file LinearClassifier.h.

virtual const char* get_name ( void   )  const [virtual]

Returns the name of the SGSerializable instance. It MUST BE the CLASS NAME without the prefixed `C'.

Returns:
name of the SGSerializable

Implements CSGObject.

Reimplemented in CLDA, CLPBoost, CLPM, CPerceptron, CSubGradientLPM, CDomainAdaptationSVMLinear, CLibLinear, CSubGradientSVM, CSVMLin, CSVMOcas, and CSVMSGD.

Definition at line 180 of file LinearClassifier.h.

void get_w ( float64_t **  dst_w,
int32_t *  dst_dims 
)

get w (swig compatible)

Parameters:
dst_w store w in this argument
dst_dims dimension of w

Definition at line 90 of file LinearClassifier.h.

void get_w ( float64_t *&  dst_w,
int32_t &  dst_dims 
)

get w

Parameters:
dst_w store w in this argument
dst_dims dimension of w

Definition at line 78 of file LinearClassifier.h.

bool load ( FILE *  srcfile  )  [virtual]

load from file

Parameters:
srcfile file to load from
Returns:
if loading was successful

Reimplemented from CClassifier.

Definition at line 32 of file LinearClassifier.cpp.

bool save ( FILE *  dstfile  )  [virtual]

save to file

Parameters:
dstfile file to save to
Returns:
if saving was successful

Reimplemented from CClassifier.

Definition at line 39 of file LinearClassifier.cpp.

void set_bias ( float64_t  b  ) 

set bias

Parameters:
b new bias

Definition at line 117 of file LinearClassifier.h.

virtual void set_features ( CDotFeatures feat  )  [virtual]

set features

Parameters:
feat features to set

Reimplemented in CLDA, CLPBoost, and CLPM.

Definition at line 149 of file LinearClassifier.h.

void set_w ( float64_t src_w,
int32_t  src_w_dim 
)

set w

Parameters:
src_w new w
src_w_dim dimension of new w

Definition at line 105 of file LinearClassifier.h.


Member Data Documentation

float64_t bias [protected]

bias

Definition at line 189 of file LinearClassifier.h.

CDotFeatures* features [protected]

features

Definition at line 191 of file LinearClassifier.h.

float64_t* w [protected]

w

Definition at line 187 of file LinearClassifier.h.

int32_t w_dim [protected]

dimension of w

Definition at line 185 of file LinearClassifier.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation