How to Write a MedPredictor
MedPredictor is Classifier/Regressor that inputs the features matrix and output prediction/s. It is being executed after FeatureProcessors
MedPredictor in MedModel follow a defined sequence of method calls. Hereβs the typical lifecycle:
-
Constructor - Initializes the MedPredictor object.
-
init_defaults() - Sets default values for the predictor. Be sure to update
classifier_type
to reflect the predictor type. -
Initialization - During learning:
Implementinit(map<string, string>& mapper)
to parse parameters from a key-value map (usingSerializableObject::init_from_string
).
Medial pipeline will initializefeatures_count
andmodel_features
that when we apply the modle we can make sure all and only needed features are inputed to the model. You might want to settranspose_for_learn
,transpose_for_predict
- if transpose of features matrix is needed for this type of predictor You might want to set (legacy and almost not used. Please use Feature Processors) to normalize the inputs:normalize_for_learn
,normalize_y_for_learn
,normalize_for_predict
- During application:
Arguments are loaded from disk. Parameters stored viaADD_SERIALIZATION_FUNCS
are restored automatically. -
Learning Phase -
learn()
Implements any learning logic needed during training. -
Applying Phase -
apply()
orpredict_single()
for single patient (more efficient setup for single patient, some preparation are done prior) Applies the predictor to calculate the score
Steps to Implement a MedPredictor
-
Create Class Files - Create a new
.h
header and.cpp
source file for your predictor class. IncludeMedAlgo.h
in your header. -
Set Default Values - Implement
init_defaults()
or set defaults in the constructor. -
Parameter Initialization - Override
init(map<string, string>& mapper)
to parse external parameters. -
Serialization - Add
MEDSERIALIZE_SUPPORT($CLASS_NAME)
at the end of your header file (replace$CLASS_NAME
). - AddADD_CLASS_NAME($CLASS_NAME)
in the public section of your class. - UseADD_SERIALIZATION_FUNCS
to specify which parameters should be saved after learning. Do not include temporary or repository-specific variables. -
Learning - Implement
learn()
for any required training logic. -
Apply - Implement
apply()
to calculate the score. If there is more efficient calculate for single call, than also implementpredict_single()
-
Register Your Predictor in the Header (
MedAlgo.h
) - Add a new type toMedPredictorTypes
beforeMODEL_LAST
. In the documentation comment, specify the name inMedPredictorTypes
for Doxygen reference. -
Register Your Feature Processor in the Source (
MedAlgo.cpp
) - Add your type conversion topredictor_type_to_name
dictionary - Add your class toMedPredictor::new_polymorphic
- Add your class toMedPredictor::make_predictor(MedPredictorTypes model_type)