Class LinearClassifier is a generic interface for all kinds of linear classifiers.
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 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 encapsulating all the required operations (like the dot product). The decision function is thus
The following linear classifiers are implemented
Definition at line 60 of file LinearClassifier.h.
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 CLabels * | classify () |
virtual CLabels * | classify (CFeatures *data) |
virtual CDotFeatures * | get_features () |
virtual const char * | get_name (void) const |
Protected Attributes | |
int32_t | w_dim |
float64_t * | w |
float64_t | bias |
CDotFeatures * | features |
default constructor
Definition at line 16 of file LinearClassifier.cpp.
~CLinearClassifier | ( | ) | [virtual] |
Definition at line 26 of file LinearClassifier.cpp.
CLabels * classify | ( | ) | [virtual] |
classify all examples
Implements CClassifier.
Definition at line 46 of file LinearClassifier.cpp.
classify objects
data | (test)data to be classified |
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 | ( | ) |
virtual CDotFeatures* 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 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)
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
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
srcfile | file to load from |
Reimplemented from CClassifier.
Definition at line 32 of file LinearClassifier.cpp.
bool save | ( | FILE * | dstfile | ) | [virtual] |
save to file
dstfile | file to save to |
Reimplemented from CClassifier.
Definition at line 39 of file LinearClassifier.cpp.
void set_bias | ( | float64_t | b | ) |
virtual void set_features | ( | CDotFeatures * | feat | ) | [virtual] |
set features
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
src_w | new w | |
src_w_dim | dimension of new w |
Definition at line 105 of file LinearClassifier.h.
bias
Definition at line 189 of file LinearClassifier.h.
CDotFeatures* features [protected] |
features
Definition at line 191 of file LinearClassifier.h.
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.