Medial Code Documentation
Loading...
Searching...
No Matches
MedLinearModel.h
1#ifndef __LINEAR_MODEL_H__
2#define __LINEAR_MODEL_H__
4#include <MedAlgo/MedAlgo/PredictiveModel.h>
6
7using namespace std;
8
13{
14public:
18 int init(map<string, string>& mapper) { return set_params(mapper); }
19 int set_params(map<string, string>& mapper);
20
21 subGradientFunction getSubGradients();
22 subGradientFunction getSubGradientsAUC();
23 subGradientFunction getSubGradientsSvm();
24 double predict(const vector<float> &input) const;
25 void predict(const vector<vector<float>> &inputs, vector<double> &preds) const;
26 PredictiveModel *clone() const;
27
28 void print(const vector<string> &signalNames) const;
29 void set_normalization(const vector<float> &meanShift, const vector<float> &factors);
30 void apply_normalization(vector<vector<float>> &input) const;
31 void get_normalization(vector<float> &meanShift, vector<float> &factors) const;
32
33 //Set Loss Fucntions to learn:
34 double(*loss_function)(const vector<double> &got, const vector<float> &y, const vector<float> *weights);
36 double(*loss_function_step)(const vector<double> &, const vector<float> &, const vector<double> &, const vector<float> *);
40 float block_num;
41 bool norm_l1;
45 int min_cat;
46 bool print_auc = false;
47 bool normalize = true;
48
49 //MedPredictor Api:
50 int Learn(float *x, float *y, const float *w, int nsamples, int nftrs);
51 int Predict(float *x, float *&preds, int nsamples, int nftrs) const;
52
53 void calc_feature_importance(vector<float> &features_importance_scores,
54 const string &general_params, const MedFeatures *features);
55
56 ADD_CLASS_NAME(MedLinearModel)
58
59private:
60 vector<float> _meanShift;
61 vector<float> _factor;
62 bool mark_learn_finish;
63};
64
65
66double _linear_loss_target_auc(const vector<double> &preds, const vector<float> &y, const vector<float> *weights);
67double _linear_loss_step_auc(const vector<double> &preds, const vector<float> &y, const vector<double> &params, const vector<float> *weights);
68double _linear_loss_step_auc_fast(const vector<double> &preds, const vector<float> &y, const vector<float> *weights);
69double _linear_loss_target_work_point(const vector<double> &preds, const vector<float> &y, const vector<float> *weights);
70double _linear_loss_step_work_point(const vector<double> &preds, const vector<float> &y, const vector<double> &model_params, const vector<float> *weights);
71double _linear_loss_target_rmse(const vector<double> &preds, const vector<float> &y, const vector<float> *weights);
72double _linear_loss_step_rmse(const vector<double> &preds, const vector<float> &y, const vector<double> &model_params, const vector<float> *weights);
73double _linear_loss_target_svm(const vector<double> &preds, const vector<float> &y, const vector<float> *weights);
74double _linear_loss_step_svm(const vector<double> &preds, const vector<float> &y, const vector<double> &model_params, const vector<float> *weights);
75
77
78#endif
79
MedAlgo - APIs to different algorithms: Linear Models, RF, GBM, KNN, and more.
An Abstract class that can be serialized and written/read from file.
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:122
#define MEDSERIALIZE_SUPPORT(Type)
Definition SerializableObject.h:108
A class for holding features data as a virtual matrix
Definition MedFeatures.h:47
Linear Model with customizable SGD support.
Definition MedLinearModel.h:13
subGradientFunction getSubGradients()
Subgradient of RMSE loss function.
Definition MedLinearModel.cpp:163
void apply_normalization(vector< vector< float > > &input) const
apply Normalization
Definition MedLinearModel.cpp:588
int init(map< string, string > &mapper)
The parsed fields from init command.
Definition MedLinearModel.h:18
int poly_degree
add polynom degree
Definition MedLinearModel.h:44
double(* loss_function)(const vector< double > &got, const vector< float > &y, const vector< float > *weights)
The custom loss_function.
Definition MedLinearModel.h:34
subGradientFunction getSubGradientsSvm()
Subgradient of svm loss function.
Definition MedLinearModel.cpp:287
int Learn(float *x, float *y, const float *w, int nsamples, int nftrs)
Learn should be implemented for each model.
Definition MedLinearModel.cpp:800
double(* loss_function_step)(const vector< double > &, const vector< float > &, const vector< double > &, const vector< float > *)
The custom loss_function step for sgd.
Definition MedLinearModel.h:36
subGradientFunction getSubGradientsAUC()
Subgradient of smooth auc loss function.
Definition MedLinearModel.cpp:199
int set_params(map< string, string > &mapper)
Definition MedLinearModel.cpp:869
int print_steps
how many prints for learn to print
Definition MedLinearModel.h:42
void print(const vector< string > &signalNames) const
print model to stdout
Definition MedLinearModel.cpp:559
int Predict(float *x, float *&preds, int nsamples, int nftrs) const
Predict should be implemented for each model.
Definition MedLinearModel.cpp:623
bool norm_l1
The blocking norm should be n1 or n2?
Definition MedLinearModel.h:41
PredictiveModel * clone() const
copy model
Definition MedLinearModel.cpp:601
int min_cat
control minimal samples per categ in categories
Definition MedLinearModel.h:45
float block_num
The blocking norm for parameter search in sgd.
Definition MedLinearModel.h:40
double learning_rate
The learning rate of sgd.
Definition MedLinearModel.h:39
bool print_auc
internal var if o print also auc metric
Definition MedLinearModel.h:46
int tot_steps
The total iteration count of sgd.
Definition MedLinearModel.h:38
bool print_model
If true will print model coeff in the end.
Definition MedLinearModel.h:43
bool normalize
iof true will do internal method for normalizing
Definition MedLinearModel.h:47
int sample_count
The sample count of sgd.
Definition MedLinearModel.h:37
void set_normalization(const vector< float > &meanShift, const vector< float > &factors)
Normalization.
Definition MedLinearModel.cpp:578
Base Interface for predictor.
Definition MedAlgo.h:78
int features_count
The model features count used in Learn, to validate when caling predict.
Definition MedAlgo.h:96
MedPredictorTypes classifier_type
The Predicotr enum type.
Definition MedAlgo.h:80
vector< string > model_features
The model features used in Learn, to validate when caling predict.
Definition MedAlgo.h:93
Predictive Model is abstract class of predictor model which has parameters for GD or SGD uses it also...
Definition PredictiveModel.h:13
vector< double > model_params
model parameters
Definition PredictiveModel.h:23
Definition StdDeque.h:58