Public Member Functions | Protected Member Functions | Protected Attributes

CLinearMachine Class Reference


Detailed Description

Class LinearMachine is a generic interface for all kinds of linear machines like 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 61 of file LinearMachine.h.

Inheritance diagram for CLinearMachine:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CLinearMachine ()
virtual ~CLinearMachine ()
void get_w (float64_t *&dst_w, int32_t &dst_dims)
SGVector< float64_tget_w ()
void set_w (SGVector< float64_t > src_w)
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 CLabelsapply ()
virtual CLabelsapply (CFeatures *data)
virtual float64_t apply (int32_t vec_idx)
 get output for example "vec_idx"
virtual CDotFeaturesget_features ()
virtual const char * get_name () const

Protected Member Functions

virtual void store_model_features ()

Protected Attributes

int32_t w_dim
float64_tw
float64_t bias
CDotFeaturesfeatures

Constructor & Destructor Documentation

CLinearMachine (  ) 

default constructor

Definition at line 16 of file LinearMachine.cpp.

~CLinearMachine (  )  [virtual]

Definition at line 26 of file LinearMachine.cpp.


Member Function Documentation

CLabels * apply (  )  [virtual]

apply linear machine to all examples

Returns:
resulting labels

Implements CMachine.

Definition at line 46 of file LinearMachine.cpp.

CLabels * apply ( CFeatures data  )  [virtual]

apply linear machine to data

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

Implements CMachine.

Definition at line 61 of file LinearMachine.cpp.

virtual float64_t apply ( int32_t  vec_idx  )  [virtual]

get output for example "vec_idx"

Reimplemented from CMachine.

Definition at line 157 of file LinearMachine.h.

float64_t get_bias (  ) 

get bias

Returns:
bias

Definition at line 113 of file LinearMachine.h.

virtual CDotFeatures* get_features (  )  [virtual]

get features

Returns:
features

Definition at line 166 of file LinearMachine.h.

virtual const char* get_name (  )  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 CAveragedPerceptron, CLDA, CPerceptron, CDomainAdaptationSVMLinear, CLibLinear, CSGDQN, CSubGradientSVM, CSVMLin, CSVMOcas, and CSVMSGD.

Definition at line 173 of file LinearMachine.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 73 of file LinearMachine.h.

SGVector<float64_t> get_w (  ) 

get w

Returns:
weight vector

Definition at line 84 of file LinearMachine.h.

bool load ( FILE *  srcfile  )  [virtual]

load from file

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

Reimplemented from CMachine.

Definition at line 32 of file LinearMachine.cpp.

bool save ( FILE *  dstfile  )  [virtual]

save to file

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

Reimplemented from CMachine.

Definition at line 39 of file LinearMachine.cpp.

void set_bias ( float64_t  b  ) 

set bias

Parameters:
b new bias

Definition at line 104 of file LinearMachine.h.

virtual void set_features ( CDotFeatures feat  )  [virtual]

set features

Parameters:
feat features to set

Reimplemented in CLDA.

Definition at line 136 of file LinearMachine.h.

void set_w ( SGVector< float64_t src_w  ) 

set w

Parameters:
src_w new w

Definition at line 93 of file LinearMachine.h.

virtual void store_model_features (  )  [protected, virtual]

Stores feature data of underlying model. Does nothing because Linear machines store the normal vector of the separating hyperplane and therefore the model anyway

Reimplemented from CMachine.

Definition at line 180 of file LinearMachine.h.


Member Data Documentation

float64_t bias [protected]

bias

Definition at line 188 of file LinearMachine.h.

CDotFeatures* features [protected]

features

Definition at line 190 of file LinearMachine.h.

float64_t* w [protected]

w

Definition at line 186 of file LinearMachine.h.

int32_t w_dim [protected]

dimension of w

Definition at line 184 of file LinearMachine.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