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

Detailed Description

Class OnlineLinearMachine is a generic interface for linear machines like classifiers which work through online algorithms.

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 arbitrary feature type, e.g. dense and sparse and even string based features. This is implemented by using CStreamingDotFeatures 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. \]

Definition at line 49 of file OnlineLinearMachine.h.

Inheritance diagram for COnlineLinearMachine:
Inheritance graph
[legend]

Public Member Functions

 COnlineLinearMachine ()
virtual ~COnlineLinearMachine ()
virtual void get_w (float32_t *&dst_w, int32_t &dst_dims)
virtual void get_w (float64_t *&dst_w, int32_t &dst_dims)
virtual SGVector< float32_tget_w ()
virtual void set_w (float32_t *src_w, int32_t src_w_dim)
virtual void set_w (float64_t *src_w, int32_t src_w_dim)
virtual void set_bias (float32_t b)
virtual float32_t get_bias ()
virtual bool load (FILE *srcfile)
virtual bool save (FILE *dstfile)
virtual void set_features (CStreamingDotFeatures *feat)
virtual CLabelsapply ()
virtual CLabelsapply (CFeatures *data)
virtual float64_t apply (int32_t vec_idx)
 get output for example "vec_idx"
virtual float32_t apply (float32_t *vec, int32_t len)
virtual float32_t apply_to_current_example ()
virtual CStreamingDotFeaturesget_features ()
virtual const char * get_name () const
- 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 Attributes

int32_t w_dim
float32_tw
float32_t bias
CStreamingDotFeaturesfeatures
- Protected Attributes inherited from CMachine
float64_t max_train_time
CLabelslabels
ESolverType solver_type
bool m_store_model_features

Additional Inherited Members

- Public Attributes inherited from CSGObject
SGIOio
Parallelparallel
Versionversion
Parameterm_parameters
Parameterm_model_selection_parameters
- Protected Member Functions inherited from CMachine
virtual bool train_machine (CFeatures *data=NULL)
virtual void store_model_features ()

Constructor & Destructor Documentation

default constructor

Definition at line 16 of file OnlineLinearMachine.cpp.

~COnlineLinearMachine ( )
virtual

Definition at line 24 of file OnlineLinearMachine.cpp.

Member Function Documentation

CLabels * apply ( )
virtual

apply linear machine to all examples

Returns
resulting labels

Implements CMachine.

Definition at line 47 of file OnlineLinearMachine.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 74 of file OnlineLinearMachine.cpp.

virtual float64_t apply ( int32_t  vec_idx)
virtual

get output for example "vec_idx"

Reimplemented from CMachine.

Definition at line 178 of file OnlineLinearMachine.h.

float32_t apply ( float32_t vec,
int32_t  len 
)
virtual

apply linear machine to one vector

Parameters
vecfeature vector
lenlength of vector
Returns
classified label

Definition at line 84 of file OnlineLinearMachine.cpp.

float32_t apply_to_current_example ( )
virtual

apply linear machine to vector currently being processed

Returns
classified label

Definition at line 89 of file OnlineLinearMachine.cpp.

virtual float32_t get_bias ( )
virtual

get bias

Returns
bias

Definition at line 133 of file OnlineLinearMachine.h.

virtual CStreamingDotFeatures* get_features ( )
virtual

get features

Returns
features

Definition at line 205 of file OnlineLinearMachine.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 CVowpalWabbit, COnlineSVMSGD, and COnlineLibLinear.

Definition at line 212 of file OnlineLinearMachine.h.

virtual void get_w ( float32_t *&  dst_w,
int32_t &  dst_dims 
)
virtual

get w

Parameters
dst_wstore w in this argument
dst_dimsdimension of w

Definition at line 61 of file OnlineLinearMachine.h.

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

Get w as a new float64_t array

Parameters
dst_wstore w in this argument
dst_dimsdimension of w

Definition at line 74 of file OnlineLinearMachine.h.

virtual SGVector<float32_t> get_w ( )
virtual

get w

Returns
weight vector

Definition at line 87 of file OnlineLinearMachine.h.

bool load ( FILE *  srcfile)
virtual

load from file

Parameters
srcfilefile to load from
Returns
if loading was successful

Reimplemented from CMachine.

Definition at line 33 of file OnlineLinearMachine.cpp.

bool save ( FILE *  dstfile)
virtual

save to file

Parameters
dstfilefile to save to
Returns
if saving was successful

Reimplemented from CMachine.

Definition at line 40 of file OnlineLinearMachine.cpp.

virtual void set_bias ( float32_t  b)
virtual

set bias

Parameters
bnew bias

Definition at line 124 of file OnlineLinearMachine.h.

virtual void set_features ( CStreamingDotFeatures feat)
virtual

set features

Parameters
featfeatures to set

Definition at line 156 of file OnlineLinearMachine.h.

virtual void set_w ( float32_t src_w,
int32_t  src_w_dim 
)
virtual

set w

Parameters
src_wnew w
src_w_dimdimension of new w

Definition at line 97 of file OnlineLinearMachine.h.

virtual void set_w ( float64_t src_w,
int32_t  src_w_dim 
)
virtual

Set weight vector from a float64_t vector

Parameters
src_wnew w
src_w_dimdimension of new w

Definition at line 111 of file OnlineLinearMachine.h.

Member Data Documentation

float32_t bias
protected

bias

Definition at line 220 of file OnlineLinearMachine.h.

CStreamingDotFeatures* features
protected

features

Definition at line 222 of file OnlineLinearMachine.h.

float32_t* w
protected

w

Definition at line 218 of file OnlineLinearMachine.h.

int32_t w_dim
protected

dimension of w

Definition at line 216 of file OnlineLinearMachine.h.


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

SHOGUN Machine Learning Toolbox - Documentation