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 55 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 CLabels * | classify (CLabels *output=NULL) |
virtual void | set_features (CDotFeatures *feat) |
virtual CDotFeatures * | get_features () |
Protected Attributes | |
int32_t | w_dim |
float64_t * | w |
float64_t | bias |
CDotFeatures * | features |
CLinearClassifier::CLinearClassifier | ( | ) |
default constructor
Definition at line 13 of file LinearClassifier.cpp.
CLinearClassifier::~CLinearClassifier | ( | ) | [virtual] |
Definition at line 18 of file LinearClassifier.cpp.
classify all examples
output | resulting labels |
Reimplemented from CClassifier.
Definition at line 34 of file LinearClassifier.cpp.
virtual float64_t CLinearClassifier::classify_example | ( | int32_t | vec_idx | ) | [virtual] |
get output for example "vec_idx"
Reimplemented from CClassifier.
Definition at line 63 of file LinearClassifier.h.
float64_t CLinearClassifier::get_bias | ( | ) |
virtual CDotFeatures* CLinearClassifier::get_features | ( | ) | [virtual] |
void CLinearClassifier::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 85 of file LinearClassifier.h.
void CLinearClassifier::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 73 of file LinearClassifier.h.
bool CLinearClassifier::load | ( | FILE * | srcfile | ) | [virtual] |
load from file
srcfile | file to load from |
Reimplemented from CClassifier.
Definition at line 24 of file LinearClassifier.cpp.
bool CLinearClassifier::save | ( | FILE * | dstfile | ) | [virtual] |
save to file
dstfile | file to save to |
Reimplemented from CClassifier.
Definition at line 29 of file LinearClassifier.cpp.
void CLinearClassifier::set_bias | ( | float64_t | b | ) |
virtual void CLinearClassifier::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 CLinearClassifier::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 100 of file LinearClassifier.h.
float64_t CLinearClassifier::bias [protected] |
bias
Definition at line 168 of file LinearClassifier.h.
CDotFeatures* CLinearClassifier::features [protected] |
features
Definition at line 170 of file LinearClassifier.h.
float64_t* CLinearClassifier::w [protected] |
w
Definition at line 166 of file LinearClassifier.h.
int32_t CLinearClassifier::w_dim [protected] |
dimension of w
Definition at line 164 of file LinearClassifier.h.