Class OnlineLinearMachine is a generic interface for linear machines like classifiers which work through online algorithms.
A linear classifier computes
where are the weights assigned to each feature in training and
the bias.
To implement a linear classifier all that is required is to define the train() function that delivers 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 encapsulating all the required operations (like the dot product). The decision function is thus
Definition at line 49 of file OnlineLinearMachine.h.
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_t > | get_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 CLabels * | apply () |
virtual CLabels * | apply (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 CStreamingDotFeatures * | get_features () |
virtual const char * | get_name () const |
Protected Attributes | |
int32_t | w_dim |
float32_t * | w |
float32_t | bias |
CStreamingDotFeatures * | features |
default constructor
Definition at line 16 of file OnlineLinearMachine.cpp.
~COnlineLinearMachine | ( | ) | [virtual] |
Definition at line 24 of file OnlineLinearMachine.cpp.
CLabels * apply | ( | ) | [virtual] |
apply linear machine to all examples
Implements CMachine.
Definition at line 47 of file OnlineLinearMachine.cpp.
apply linear machine to data
data | (test)data to be classified |
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.
apply linear machine to one vector
vec | feature vector | |
len | length of vector |
Definition at line 84 of file OnlineLinearMachine.cpp.
float32_t apply_to_current_example | ( | ) | [virtual] |
apply linear machine to vector currently being processed
Definition at line 89 of file OnlineLinearMachine.cpp.
virtual float32_t get_bias | ( | ) | [virtual] |
virtual CStreamingDotFeatures* get_features | ( | ) | [virtual] |
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'.
Implements CSGObject.
Reimplemented in COnlineLibLinear, COnlineSVMSGD, and CVowpalWabbit.
Definition at line 212 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
dst_w | store w in this argument | |
dst_dims | dimension of w |
Definition at line 74 of file OnlineLinearMachine.h.
virtual void get_w | ( | float32_t *& | dst_w, | |
int32_t & | dst_dims | |||
) | [virtual] |
get w
dst_w | store w in this argument | |
dst_dims | dimension of w |
Definition at line 61 of file OnlineLinearMachine.h.
bool load | ( | FILE * | srcfile | ) | [virtual] |
load from file
srcfile | file to load from |
Reimplemented from CMachine.
Definition at line 33 of file OnlineLinearMachine.cpp.
bool save | ( | FILE * | dstfile | ) | [virtual] |
save to file
dstfile | file to save to |
Reimplemented from CMachine.
Definition at line 40 of file OnlineLinearMachine.cpp.
virtual void set_bias | ( | float32_t | b | ) | [virtual] |
virtual void set_features | ( | CStreamingDotFeatures * | feat | ) | [virtual] |
virtual void set_w | ( | float64_t * | src_w, | |
int32_t | src_w_dim | |||
) | [virtual] |
Set weight vector from a float64_t vector
src_w | new w | |
src_w_dim | dimension of new w |
Definition at line 111 of file OnlineLinearMachine.h.
virtual void set_w | ( | float32_t * | src_w, | |
int32_t | src_w_dim | |||
) | [virtual] |
set w
src_w | new w | |
src_w_dim | dimension of new w |
Definition at line 97 of file OnlineLinearMachine.h.
bias
Definition at line 220 of file OnlineLinearMachine.h.
CStreamingDotFeatures* features [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.