Medial Code Documentation
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
MedQRF Class Reference
Inheritance diagram for MedQRF:
MedPredictor SerializableObject

Public Member Functions

 MedQRF (void *params)
 
 MedQRF (MedQRFParams &params)
 
int init (void *params)
 
virtual int set_params (map< string, string > &mapper)
 The parsed fields from init command.
 
void init_defaults ()
 
QRF_TreeType get_tree_type (string name)
 
int Learn (float *x, float *y, const float *w, int nsamples, int nftrs)
 Learn should be implemented for each model.
 
int Predict (float *x, float *&preds, int nsamples, int nftrs) const
 Predict should be implemented for each model.
 
void print (FILE *fp, const string &prefix, int level=0) const
 
void printTrees (const vector< string > &modelSignalNames, const string &outputPath) const
 
void calc_feature_importance (vector< float > &features_importance_scores, const string &general_params, const MedFeatures *features)
 
int n_preds_per_sample () const
 Number of predictions per sample. typically 1 - but some models return several per sample (for example a probability vector)
 
void prepare_predict_single ()
 
void predict_single (const vector< float > &x, vector< float > &preds) const
 
- Public Member Functions inherited from MedPredictor
int init_from_string (string initialization_text)
 
virtual int init (map< string, string > &mapper)
 Virtual to init object from parsed fields.
 
virtual int denormalize_model (float *f_avg, float *f_std, float label_avg, float label_std)
 
int learn (float *x, float *y, int nsamples, int nftrs)
 simple no weights call
 
virtual int learn (MedMat< float > &x, MedMat< float > &y, const vector< float > &wgts)
 MedMat x,y : will transpose/normalize x,y if needed by algorithm The convention is that untransposed mats are always samples x features, and transposed are features x samples.
 
int learn (MedMat< float > &x, MedMat< float > &y)
 MedMat x,y : will transpose/normalize x,y if needed by algorithm The convention is that untransposed mats are always samples x features, and transposed are features x samples.
 
int learn (MedMat< float > &x, vector< float > &y, const vector< float > &wgts)
 MedMat x, vector y: will transpose normalize x if needed (y assumed to be normalized)
 
int learn (MedMat< float > &x, vector< float > &y)
 MedMat x, vector y: will transpose normalize x if needed (y assumed to be normalized)
 
int learn (vector< float > &x, vector< float > &y, const vector< float > &wgts, int n_samples, int n_ftrs)
 vector x,y: transpose/normalizations not done.
 
int learn (vector< float > &x, vector< float > &y, int n_samples, int n_ftrs)
 vector x,y: transpose/normalizations not done.
 
virtual int predict (MedMat< float > &x, vector< float > &preds) const
 
int predict (vector< float > &x, vector< float > &preds, int n_samples, int n_ftrs) const
 
int threaded_predict (MedMat< float > &x, vector< float > &preds, int nthreads) const
 
int learn (const MedFeatures &features)
 
int learn (const MedFeatures &features, vector< string > &names)
 
virtual int predict (MedFeatures &features) const
 
virtual void calc_feature_importance (vector< float > &features_importance_scores, const string &general_params)
 Feature Importance - assume called after learn.
 
virtual void calc_feature_contribs (MedMat< float > &x, MedMat< float > &contribs)
 Feature contributions explains the prediction on each sample (aka BUT_WHY)
 
virtual void calc_feature_contribs_conditional (MedMat< float > &mat_x_in, unordered_map< string, float > &contiditional_variables, MedMat< float > &mat_x_out, MedMat< float > &mat_contribs)
 
virtual void export_predictor (const string &output_fname)
 
int learn_prob_calibration (MedMat< float > &x, vector< float > &y, vector< float > &min_range, vector< float > &max_range, vector< float > &map_prob, int min_bucket_size=10000, float min_score_jump=0.001, float min_prob_jump=0.005, bool fix_prob_order=false)
 calibration for probability using training data
 
int convert_scores_to_prob (const vector< float > &preds, const vector< float > &min_range, const vector< float > &max_range, const vector< float > &map_prob, vector< float > &probs) const
 If you have ran learn_prob_calibration before, you have min_range,max_range,map_prob from This function - that is used to convert preds to probs.
 
int learn_prob_calibration (MedMat< float > &x, vector< float > &y, int poly_rank, vector< double > &params, int min_bucket_size=10000, float min_score_jump=0.001)
 Will create probability bins using Platt scale method.
 
template<class T , class L >
int convert_scores_to_prob (const vector< T > &preds, const vector< double > &params, vector< L > &converted) const
 Converts probability from Platt scale model.
 
virtual bool predict_single_not_implemented ()
 Prepartion function for fast prediction on single item each time.
 
virtual void predict_single (const vector< double > &x, vector< double > &preds) const
 
virtual void calc_feature_importance_shap (vector< float > &features_importance_scores, string &importance_type, const MedFeatures *features)
 
void * new_polymorphic (string derived_class_name)
 for polymorphic classes that want to be able to serialize/deserialize a pointer * to the derived class given its type one needs to implement this function to return a new to the derived class given its type (as in my_type)
 
size_t get_predictor_size ()
 
size_t predictor_serialize (unsigned char *blob)
 
- Public Member Functions inherited from SerializableObject
virtual int version () const
 Relevant for serializations.
 
virtual string my_class_name () const
 For better handling of serializations it is highly recommended that each SerializableObject inheriting class will implement the next method.
 
virtual void serialized_fields_name (vector< string > &field_names) const
 The names of the serialized fields.
 
virtual void pre_serialization ()
 
virtual void post_deserialization ()
 
virtual size_t get_size ()
 Gets bytes sizes for serializations.
 
virtual size_t serialize (unsigned char *blob)
 Serialiazing object to blob memory. return number ob bytes wrote to memory.
 
virtual size_t deserialize (unsigned char *blob)
 Deserialiazing blob to object. returns number of bytes read.
 
size_t serialize_vec (vector< unsigned char > &blob)
 
size_t deserialize_vec (vector< unsigned char > &blob)
 
virtual size_t serialize (vector< unsigned char > &blob)
 
virtual size_t deserialize (vector< unsigned char > &blob)
 
virtual int read_from_file (const string &fname)
 read and deserialize model
 
virtual int write_to_file (const string &fname)
 serialize model and write to file
 
virtual int read_from_file_unsafe (const string &fname)
 read and deserialize model without checking version number - unsafe read
 
int init_from_string (string init_string)
 Init from string.
 
int init_params_from_file (string init_file)
 
int init_param_from_file (string file_str, string &param)
 
int update_from_string (const string &init_string)
 
virtual int update (map< string, string > &map)
 Virtual to update object from parsed fields.
 
virtual string object_json () const
 

Data Fields

QRF_Forest qf
 Model.
 
MedQRFParams params
 Parameters.
 
- Data Fields inherited from MedPredictor
MedPredictorTypes classifier_type
 The Predicotr enum type.
 
bool transpose_for_learn
 True if need to transpose before learn.
 
bool normalize_for_learn
 True if need to normalize before learn.
 
bool normalize_y_for_learn
 True if need to normalize labels before learn.
 
bool transpose_for_predict
 True if need to transpose before predict.
 
bool normalize_for_predict
 True if need to normalize before predict.
 
vector< string > model_features
 The model features used in Learn, to validate when caling predict.
 
int features_count = 0
 The model features count used in Learn, to validate when caling predict.
 

Additional Inherited Members

- Static Public Member Functions inherited from MedPredictor
static MedPredictormake_predictor (string model_type)
 
static MedPredictormake_predictor (MedPredictorTypes model_type)
 
static MedPredictormake_predictor (string model_type, string params)
 
static MedPredictormake_predictor (MedPredictorTypes model_type, string params)
 
- Protected Member Functions inherited from MedPredictor
void prepare_x_mat (MedMat< float > &x, const vector< float > &wgts, int &nsamples, int &nftrs, bool transpose_needed) const
 
void predict_thread (void *p) const
 

Member Function Documentation

◆ calc_feature_importance()

void MedQRF::calc_feature_importance ( vector< float > &  features_importance_scores,
const string &  general_params,
const MedFeatures features 
)
virtual

Reimplemented from MedPredictor.

◆ get_tree_type()

QRF_TreeType MedQRF::get_tree_type ( string  name)
boost::algorithm::to_lower(name);
if (name == "binary_tree" || name == "binary")
return QRF_BINARY_TREE;
else if (name == "regression_tree" || name == "regression")
return QRF_REGRESSION_TREE;
else if (name == "categorial_chi2_tree" || name == "categorical_chi2_tree" || name == "categorial_chi2" || name == "categorical_chi2")
return QRF_CATEGORICAL_CHI2_TREE;
else if (name == "categorial_entropy_tree" || name == "categorical_entropy_tree" || name == "categorial_entropy" || name == "categorical_entropy")
return QRF_CATEGORICAL_ENTROPY_TREE;
else if (name == "categorial_multilabel_entropy_tree" || name == "categorical_multilabel_entropy")
return QRF_MULTILABEL_ENTROPY_TREE;
else
return QRF_LAST;

[MedQRF_get_types]

[MedQRF_get_types]

◆ init()

int MedQRF::init ( void *  params)
virtual

Reimplemented from MedPredictor.

◆ init_defaults()

void MedQRF::init_defaults ( )
virtual

Reimplemented from MedPredictor.

◆ Learn()

int MedQRF::Learn ( float *  x,
float *  y,
const float *  w,
int  n_samples,
int  n_ftrs 
)
virtual

Learn should be implemented for each model.

This API always assumes the data is already normalized/transposed as needed, and never changes data in x,y,w. method should support calling with w=NULL.

Reimplemented from MedPredictor.

◆ n_preds_per_sample()

int MedQRF::n_preds_per_sample ( ) const
virtual

Number of predictions per sample. typically 1 - but some models return several per sample (for example a probability vector)

Reimplemented from MedPredictor.

◆ Predict()

int MedQRF::Predict ( float *  x,
float *&  preds,
int  n_samples,
int  n_ftrs 
) const
virtual

Predict should be implemented for each model.

This API assumes x is normalized/transposed if needed. preds should either be pre-allocated or NULL - in which case the predictor should allocate it to the right size.

Reimplemented from MedPredictor.

◆ predict_single()

void MedQRF::predict_single ( const vector< float > &  x,
vector< float > &  preds 
) const
virtual

Reimplemented from MedPredictor.

◆ prepare_predict_single()

void MedQRF::prepare_predict_single ( )
virtual

Reimplemented from MedPredictor.

◆ print()

void MedQRF::print ( FILE *  fp,
const string &  prefix,
int  level = 0 
) const
virtual

Reimplemented from MedPredictor.

◆ set_params()

int MedQRF::set_params ( map< string, string > &  mapper)
virtual

The parsed fields from init command.

if (field == "ntrees") params.ntrees = stoi(entry.second);
else if (field == "maxq") params.maxq = stoi(entry.second);
else if (field == "type") params.type = get_tree_type(entry.second);
else if (field == "min_node") params.min_node = stoi(entry.second);
else if (field == "ntry") params.ntry = stoi(entry.second);
else if (field == "get_count") params.get_count = stoi(entry.second);
else if (field == "get_only_this_categ") params.get_only_this_categ = stoi(entry.second);
else if (field == "max_samp") params.max_samp = stoi(entry.second);
else if (field == "samp_factor") params.samp_factor = stof(entry.second);
else if (field == "n_categ") params.n_categ = stoi(entry.second);
else if (field == "spread") params.spread = stof(entry.second);
else if (field == "learn_nthreads") params.learn_nthreads = stoi(entry.second);
else if (field == "predict_nthreads") params.predict_nthreads = stoi(entry.second);
else if (field == "keep_all_values") params.keep_all_values = (bool)(stoi(entry.second) != 0);
else if (field == "sparse_values") params.sparse_values = (bool)(stoi(entry.second) != 0);
else if (field == "max_depth") params.max_depth = stoi(entry.second);
else if (field == "take_all_samples") params.take_all_samples = (bool)(stoi(entry.second) != 0);
else if (field == "quantiles") {
vector<string> vals;
split(vals, entry.second, boost::is_any_of(","));
params.quantiles.resize(vals.size());
for (int j = 0; j < vals.size(); j++)
params.quantiles[j] = stof(vals[j]);
}
else if (field == "sampsize") {
vector<string> vals;
split(vals, entry.second, boost::is_any_of(","));
params.samp_vec.resize(vals.size());
for (int j = 0; j < vals.size(); j++)
params.samp_vec[j] = stoi(vals[j]);
if (vals.size() == 1 && params.samp_vec[0] <= 0) { params.samp_vec.clear(); params.sampsize = NULL; }
else {
params.sampsize = &params.samp_vec[0];
}
}
else MLOG("Unknown parameter \'%s\' for QRF\n", field.c_str());
#define MLOG(fmt,...)
MLOG() - use LOCAL_SECTION and LOCAL_LEVEL.
Definition Logger.h:145
QRF_TreeType get_tree_type(string name)
Definition MedQRF.cpp:180
MedQRFParams params
Parameters.
Definition MedQRF.h:61
bool sparse_values
For keeping all values as a value-index(int):count(char) vector.
Definition MedQRF.h:36
vector< int > samp_vec
to be used when sampsize is NULL and max_samp,samp_vector > 0
Definition MedQRF.h:26
float samp_factor
if > 0 & sampsize if NULL : the maximal factor of samples between the 2 largest categories
Definition MedQRF.h:25
int max_depth
maximial depth of tree branches - if 0 no limit
Definition MedQRF.h:30
bool take_all_samples
use all samples - no sampling in building tree
Definition MedQRF.h:31
int max_samp
M if > 0 & sampsize is NULL : the maximal sampsize we will take from each category.
Definition MedQRF.h:24
bool keep_all_values
For quantile regression.
Definition MedQRF.h:35
int ntry
if ntry <= 0: ntry = (int)(sqrt((double)nfeat) + 1.0);
Definition MedQRF.h:28
vector< float > quantiles
For quantile regression.
Definition MedQRF.h:46

[MedQRF::init]

[MedQRF::init]

Reimplemented from MedPredictor.


The documentation for this class was generated from the following files: