SHOGUN
v1.1.0
|
Class LinearMachine is a generic interface for all kinds of linear machines like 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 61 of file LinearMachine.h.
Public Member Functions | |
CLinearMachine () | |
virtual | ~CLinearMachine () |
void | get_w (float64_t *&dst_w, int32_t &dst_dims) |
SGVector< float64_t > | get_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 CLabels * | apply () |
virtual CLabels * | apply (CFeatures *data) |
virtual float64_t | apply (int32_t vec_idx) |
get output for example "vec_idx" | |
virtual CDotFeatures * | get_features () |
virtual const char * | get_name () const |
![]() | |
CMachine () | |
virtual | ~CMachine () |
virtual bool | train (CFeatures *data=NULL) |
virtual void | set_labels (CLabels *lab) |
virtual CLabels * | get_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) |
![]() | |
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) |
SGIO * | get_global_io () |
void | set_global_parallel (Parallel *parallel) |
Parallel * | get_global_parallel () |
void | set_global_version (Version *version) |
Version * | get_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 Member Functions | |
virtual void | store_model_features () |
![]() | |
virtual bool | train_machine (CFeatures *data=NULL) |
![]() | |
virtual void | load_serializable_pre () throw (ShogunException) |
virtual void | load_serializable_post () throw (ShogunException) |
virtual void | save_serializable_pre () throw (ShogunException) |
virtual void | save_serializable_post () throw (ShogunException) |
Protected Attributes | |
int32_t | w_dim |
float64_t * | w |
float64_t | bias |
CDotFeatures * | features |
![]() | |
float64_t | max_train_time |
CLabels * | labels |
ESolverType | solver_type |
bool | m_store_model_features |
Additional Inherited Members | |
![]() | |
SGIO * | io |
Parallel * | parallel |
Version * | version |
Parameter * | m_parameters |
Parameter * | m_model_selection_parameters |
CLinearMachine | ( | ) |
default constructor
Definition at line 16 of file LinearMachine.cpp.
|
virtual |
Definition at line 26 of file LinearMachine.cpp.
|
virtual |
apply linear machine to all examples
Implements CMachine.
Definition at line 46 of file LinearMachine.cpp.
apply linear machine to data
data | (test)data to be classified |
Implements CMachine.
Definition at line 61 of file LinearMachine.cpp.
|
virtual |
get output for example "vec_idx"
Reimplemented from CMachine.
Definition at line 157 of file LinearMachine.h.
float64_t get_bias | ( | ) |
|
virtual |
|
virtual |
Returns the name of the SGSerializable instance. It MUST BE the CLASS NAME without the prefixed `C'.
Implements CSGObject.
Reimplemented in CSVMOcas, CSubGradientSVM, CSVMSGD, CLibLinear, CSGDQN, CDomainAdaptationSVMLinear, CLDA, CSVMLin, CAveragedPerceptron, and CPerceptron.
Definition at line 173 of file LinearMachine.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 73 of file LinearMachine.h.
|
virtual |
load from file
srcfile | file to load from |
Reimplemented from CMachine.
Definition at line 32 of file LinearMachine.cpp.
|
virtual |
save to file
dstfile | file to save to |
Reimplemented from CMachine.
Definition at line 39 of file LinearMachine.cpp.
void set_bias | ( | float64_t | b | ) |
|
virtual |
set features
feat | features to set |
Reimplemented in CLDA.
Definition at line 136 of file LinearMachine.h.
|
protectedvirtual |
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.
|
protected |
bias
Definition at line 188 of file LinearMachine.h.
|
protected |
features
Definition at line 190 of file LinearMachine.h.
|
protected |
w
Definition at line 186 of file LinearMachine.h.
|
protected |
dimension of w
Definition at line 184 of file LinearMachine.h.