Medial Code Documentation
Loading...
Searching...
No Matches
AlgoMarkerInternal.h
1#pragma once
2
3#include <string>
4#include <InfraMed/InfraMed/InfraMed.h>
5#include <InfraMed/InfraMed/MedPidRepository.h>
8#include <MedStat/MedStat/MedBootstrap.h>
9#include "InputTesters.h"
10#include "AlgoMarkerErr.h"
11#include <cmath>
12
13#undef LOCAL_SECTION
14#define LOCAL_SECTION LOG_APP
15#define LOCAL_LEVEL LOG_DEF_LEVEL
16
18public:
20 string signal_name = "";
21 int max_count = 1;
23 int time_channel = 0;
25 int val_channel = 0;
26 vector<string> sets;
27
28 // Not to be initialized:
29 vector<char> lut;
30 int init(map<string, string>& mapper) {
31 for (auto &it : mapper)
32 {
33 if (it.first == "contributer_group_name")
34 contributer_group_name = it.second;
35 else if (it.first == "signal_name")
36 signal_name = it.second;
37 else if (it.first == "max_count")
38 max_count = med_stoi(it.second);
39 else if (it.first == "max_time_window")
40 max_time_window = med_stoi(it.second);
41 else if (it.first == "time_channel")
42 time_channel = med_stoi(it.second);
43 else if (it.first == "val_channel")
44 val_channel = med_stoi(it.second);
45 else if (it.first == "time_unit")
46 time_unit = med_time_converter.string_to_type(it.second);
47 else if (it.first == "sets")
48 boost::split(sets, it.second, boost::is_any_of(","));
49 else
50 HMTHROW_AND_ERR("Error in Explainer_record_config::init - unknown parameter \"%s\"\n",
51 it.first.c_str());
52 }
53 if (contributer_group_name.empty())
54 HMTHROW_AND_ERR("Error in Explainer_record_config::init - contributer_group_name must be given\n");
55 if (signal_name.empty())
56 HMTHROW_AND_ERR("Error in Explainer_record_config::init - signal_name must be given\n");
57 return 0;
58 }
59
60 ADD_CLASS_NAME(Explainer_record_config)
62};
63
65public:
66 map<string, Explainer_record_config> records;
67
68 void read_cfg_file(const string &file);
69
70 int init(map<string, string>& mapper) {
71 for (auto &it : mapper)
72 {
73 if (it.first == "records")
74 read_cfg_file(it.second);
75 else
76 HMTHROW_AND_ERR("Error in Explainer_description_config::init - unknown parameter \"%s\"\n",
77 it.first.c_str());
78 }
79 return 0;
80 }
81
82 ADD_CLASS_NAME(Explainer_description_config)
84};
85
87public:
88 float max_threshold = 0;
89 int num_groups = 3;
90 bool use_perc = false;
92 unordered_set<string> ignore_groups_list;
96 float threshold_abs = -1;
98 vector<string> static_features_info;
99
100 // to be init before:
101 string base_dir = "";
102
103 int init(map<string, string>& mapper) {
104 for (auto &it : mapper)
105 {
106 if (it.first == "max_threshold")
107 max_threshold = med_stof(it.second);
108 else if (it.first == "num_groups")
109 num_groups = med_stoi(it.second);
110 else if (it.first == "total_max_reasons")
111 total_max_reasons = med_stoi(it.second);
112 else if (it.first == "total_max_pos_reasons")
113 total_max_pos_reasons = med_stoi(it.second);
114 else if (it.first == "total_max_neg_reasons")
115 total_max_neg_reasons = med_stoi(it.second);
116 else if (it.first == "threshold_abs")
117 threshold_abs = med_stof(it.second);
118 else if (it.first == "threshold_percentage")
119 threshold_percentage = med_stof(it.second);
120 else if (it.first == "use_perc")
121 use_perc = med_stoi(it.second) > 0;
122 else if (it.first == "static_features_info")
123 boost::split(static_features_info, it.second, boost::is_any_of(","));
124 else if (it.first == "ignore_groups_list") {
125 vector<string> tokens;
126 boost::split(tokens, it.second, boost::is_any_of(","));
127 ignore_groups_list.insert(tokens.begin(), tokens.end());
128 }
129 else if (it.first == "cfg") {
130 if (it.second != "" && it.second[0] != '/' && it.second[0] != '\\' && !base_dir.empty())
131 cfg.read_cfg_file(base_dir + path_sep() + it.second);
132 else
133 cfg.read_cfg_file(it.second);
134 }
135 else
136 HMTHROW_AND_ERR("Error in Explainer_parameters::init - unknown parameter \"%s\"\n",
137 it.first.c_str());
138 }
139 if (max_threshold < 0)
140 HMTHROW_AND_ERR("Error in Explainer_parameters::init - max_threshold should be positive\n");
141
142 return 0;
143 }
144
145 ADD_CLASS_NAME(Explainer_parameters)
147};
148
149//===============================================================================
150// MedAlgoMarkerInternal - a mid-way API class : hiding all details of
151// implementation that are specific to the base classes (MedRepository, MedSamples, MedModel)
152// that we use today.
153// All functions assume c style to allow for easy export to C#/.NET
154//===============================================================================
156private:
157 // we force working ONLY using the API
158
160 MedModel model;
161 MedSamples samples;
162 unordered_map<int, unordered_map<string, unordered_set<string>>> unknown_codes;
163 Explainer_parameters explainer_params;
164 //InputSanityTester ist;
165 map<string, map<string, float>> mbr;
166 string default_threshold = "";
167
168 string name;
169 string model_fname;
170 string rep_fname;
171 vector<int> pids;
172 int model_end_stage = MED_MDL_END;
173 bool model_init_done = false;
174 bool model_rep_done = false;
175public:
176
177 MedPidRepository & get_rep() { return rep; }
178 //========================================================
179 // Initializations
180 //========================================================
181
182 // init name
183 void set_name(const char *_name) { name = string(_name); }
184 void set_model_end_stage(int _model_end_stage) { model_end_stage = _model_end_stage; };
185
186 // init repository config
187 int init_rep_config(const char *config_fname) {
188 rep.switch_to_in_mem_mode();
189 if (rep.MedRepository::init(string(config_fname)) < 0) return -1;
190
191 return 0;
192 }
193
194 // set time_unit env for repositories and models
195 int set_time_unit_env(int time_unit) {
196 global_default_time_unit = time_unit;
197 return 0;
198 }
199
200 // init pids
201 void set_pids(int *_pids, int npids) { pids.clear(); pids.assign(_pids, _pids + npids); }
202
203 // init rep , model , samples
204 int init_rep_with_file_data(const char *_rep_fname) {
205 rep.clear();
206 rep_fname = string(_rep_fname);
207 vector<string> sigs = {};
208 return (rep.read_all(rep_fname, pids, sigs));
209 }
210
211 // init model
212 int init_model_from_file(const char *_model_fname) { model.clear(); model.verbosity = 0; return (model.read_from_file(string(_model_fname))); }
213 int model_check_required_signals() {
214 int ret = 0;
215 vector<string> req_sigs;
216 model.get_required_signal_names(req_sigs);
217 for (const auto& s : req_sigs)
218 if (0 == rep.sigs.Name2Sid.count(s)) {
219 ret = -1;
220 fprintf(stderr, "ERROR: AM model requires signal '%s' but signal does not exist in AM repository .signals file\n", s.c_str());
221 }
222 return ret;
223 }
224
225 // init model for apply
226 int init_model_for_apply() {
227 global_logger.log(LOG_APP, LOG_DEF_LEVEL, "Init MedModel for Apply\n");
228 model_init_done = true;
229 return model.init_model_for_apply(rep, MED_MDL_APPLY_FTR_GENERATORS, MED_MDL_END);
230 }
231
232 void fit_model_to_rep() {
233 model.fit_for_repository(rep);
234 }
235
236 int init_model_for_rep() {
237 //global_logger.log(LOG_APP, LOG_DEF_LEVEL, "Init MedModel for Rep\n");
238 if (!model_rep_done) {
239 model_rep_done = true;
240 return model.init_model_for_apply(rep, MED_MDL_APPLY_FTR_GENERATORS, MED_MDL_APPLY_FTR_PROCESSORS);
241 }
242 return 0;
243 }
244
245 unordered_map<string, unordered_set<string>> *get_unknown_codes(int pid) {
246 return &unknown_codes[pid];
247 }
248 // init samples
249 int init_samples(int *pids, int *times, int n_samples) { clear_samples(); int rc = insert_samples(pids, times, n_samples); samples.normalize(); return rc; }
250 int init_samples(int pid, int time) { return init_samples(&pid, &time, 1); } // single prediction point initiation
251
252 // init input_tester
253 //int init_input_tester(const char *_fname) { return ist.read_config(string(_fname)); }
254
255 void add_json_dict(json &js) { rep.dict.add_json(js); }
256
257 bool model_initiated() { return model_init_done; }
258
259 //========================================================
260 // Loading data to rep
261 //========================================================
262
263 // init loading : actions that must be taken BEFORE any loading starts
264 int data_load_init() { unknown_codes.clear(); rep.switch_to_in_mem_mode(); return 0; }
265
266 // load n_elems for a pid,sig
267 int data_load_pid_sig(int pid, const char *sig_name, int *times, float *vals, int n_elems) {
268 int sid = rep.sigs.Name2Sid[string(sig_name)];
269 if (sid < 0) return -1; // no such signal
270 int n_times = n_elems * rep.sigs.Sid2Info[sid].n_time_channels, n_vals = n_elems * rep.sigs.Sid2Info[sid].n_val_channels;
271 if (times == NULL) n_times = 0;
272 if (vals == NULL) n_vals = 0;
273 return rep.in_mem_rep.insertData(pid, sid, times, vals, n_times, n_vals);
274 }
275
276 // load pid,sig with vectors of times and vals
277 int data_load_pid_sig(int pid, const char *sig_name, int *times, int n_times, float *vals, int n_vals,
278 map<pair<int, int>, pair<int, vector<char>>> *data = NULL) {
279 int sid = rep.sigs.Name2Sid[string(sig_name)];
280 if (sid < 0) return -1; // no such signal
281 if (data == NULL)
282 data = &rep.in_mem_rep.data;
283 return rep.in_mem_rep.insertData_to_buffer(pid, sid, times, vals, n_times, n_vals, rep.sigs, *data);
284 }
285
286 // load a single element for a pid,sig
287 int data_load_pid_sig(int pid, const char *sig_name, int *times, float *vals) { return data_load_pid_sig(pid, sig_name, times, vals, 1); }
288
289 // end loading : actions that must be taken AFTER all loading was done, and BEFORE we calculate the predictions
290 int data_load_end() { return rep.in_mem_rep.sortData(); }
291
292 void get_rep_signals(unordered_set<string> &sigs)
293 {
294 for (auto &sig : rep.sigs.signals_names)
295 {
296 sigs.insert(sig);
297 }
298 }
299 // returns the available signals
300
301 //========================================================
302 // Samples
303 //========================================================
304
305 // clear prediction points BEFORE a new set of predictions is done using the same instance
306 void clear_samples() { samples.clear(); }
307
308 // insert prediction points
309 int insert_samples(int *pids, int *times, int n_samples) {
310 for (int i = 0; i < n_samples; i++)
311 samples.insertRec(pids[i], times[i]);
312 return 0;
313 }
314
315 int insert_sample(int pid, int time) { return insert_samples(&pid, &time, 1); }
316
317 //MedSample *get_sample(int idx) { if (idx>=0 && idx<samples.get_size()) return & }
318
319 // normalize samples must be called after finishing inserting all samples.
320 int normalize_samples() { samples.normalize(); return 0; }
321
322 MedSamples *get_samples_ptr() { return &samples; }
323
324 //========================================================
325 // Calculate predictions
326 //========================================================
327 // note that if (_pids,times) are not sorted, they will be changed and sorted.
328 int get_preds(int *_pids, int *times, float *preds, int n_samples) {
329
330 // init_samples
331 init_samples(_pids, times, n_samples);
332
333 return get_raw_preds(_pids, times, preds);
334 }
335
336 int get_preds(int *_pids, int *times, float *preds, int n_samples,
337 const vector<Effected_Field> &requested_fields, MedPidRepository *_rep=NULL) {
338
339 // init_samples
340 init_samples(_pids, times, n_samples);
341 if (_rep == NULL)
342 _rep = &this->rep;
343 return get_raw_preds(_pids, times, preds, requested_fields, _rep);
344 }
345
346 int get_raw_preds(int *_pids, int *times, float *preds,
347 const vector<Effected_Field> &requested_fields, MedPidRepository *_rep) {
348
349 try {
350
351 try {
352 // run model to calculate predictions
353 if (!samples.idSamples.empty())
354 model.no_init_apply_partial(*_rep, samples, requested_fields);
355 }
356 catch (...) {
357 fprintf(stderr, "Caught an exception in no_init_apply_partial\n");
358 return -1;
359 }
360
361 // export pids, times and preds to c arrays
362 int j = 0;
363 if (preds != NULL) {
364 for (auto& idSample : samples.idSamples)
365 for (auto& sample : idSample.samples) {
366 _pids[j] = sample.id;
367 times[j] = sample.time;
368 preds[j] = sample.prediction.size() > 0 ? sample.prediction[0] : (float)AM_UNDEFINED_VALUE; // This is Naive - but works for simple predictors giving the Raw score.
369 j++;
370 }
371 }
372
373 return 0;
374 }
375 catch (int &exception_code) {
376 fprintf(stderr, "Caught an exception code: %d\n", exception_code);
377 return -1; // exception_code;
378 }
379 catch (...) {
380 fprintf(stderr, "Caught Something...\n");
381 return -1;
382 }
383 }
384
385
386 int get_raw_preds(int *_pids, int *times, float *preds) {
387
388 try {
389
390 try {
391 // run model to calculate predictions
392 if (!samples.idSamples.empty())
393 if (model.no_init_apply(rep, samples, (MedModelStage)0, (MedModelStage)model_end_stage) < 0) {
394 fprintf(stderr, "ERROR: MedAlgoMarkerInternal::get_preds FAILED.");
395 return -1;
396 }
397 }
398 catch (...) {
399 fprintf(stderr, "Caught an exception in no_init_apply\n");
400 return -1;
401 }
402
403 // export pids, times and preds to c arrays
404 int j = 0;
405 if (preds != NULL) {
406 for (auto& idSample : samples.idSamples)
407 for (auto& sample : idSample.samples) {
408 _pids[j] = sample.id;
409 times[j] = sample.time;
410 preds[j] = sample.prediction.size() > 0 ? sample.prediction[0] : (float)AM_UNDEFINED_VALUE; // This is Naive - but works for simple predictors giving the Raw score.
411 j++;
412 }
413 }
414
415 return 0;
416 }
417 catch (int &exception_code) {
418 fprintf(stderr, "Caught an exception code: %d\n", exception_code);
419 return -1; // exception_code;
420 }
421 catch (...) {
422 fprintf(stderr, "Caught Something...\n");
423 return -1;
424 }
425 }
426
427 int get_preds(MedSamples &_samples, float *preds) {
428
429 samples = _samples;
430
431 // run model to calculate predictions
432 if (model.no_init_apply(rep, samples, (MedModelStage)0, (MedModelStage)model_end_stage) < 0) {
433 fprintf(stderr, "ERROR: MedAlgoMarkerInternal::get_preds FAILED.");
434 return -1;
435 }
436
437 // export pids, times and preds to c arrays
438 int j = 0;
439 for (auto& idSample : samples.idSamples)
440 for (auto& sample : idSample.samples) {
441 preds[j++] = sample.prediction[0]; // This is Naive - but works for simple predictors giving the Raw score.
442 }
443 return 0;
444 }
445
446 int get_pred(int *pid, int *time, float *pred) { return get_preds(pid, time, pred, 1); }
447
448
449 //========================================================
450 // Clearing - freeing mem
451 //========================================================
452 void clear() { unknown_codes.clear(); pids.clear(); model.clear(); samples.clear(); rep.in_mem_rep.clear(); rep.clear(); }
453
454 // clear_data() : leave model up, leave repository config up, but get rid of data and samples
455 void clear_data() {
456 samples.clear(); rep.in_mem_rep.clear(); unknown_codes.clear();
457 }
458
459
460 //========================================================
461 // a few more needed APIs
462 //========================================================
463 const char *get_name() { return name.c_str(); }
464
465 void write_features_mat(const string &feat_mat) { model.write_feature_matrix(feat_mat); }
466 void add_features_mat(const string &feat_mat) { model.write_feature_matrix(feat_mat, false, true); }
467
468 void get_signal_structure(string &sig, int &n_time_channels, int &n_val_channels, int* &is_categ)
469 {
470 int sid = this->rep.sigs.sid(sig);
471 if (sid <= 0) {
472 n_time_channels = 0;
473 n_val_channels = 0;
474 }
475 else {
476 n_time_channels = this->rep.sigs.Sid2Info[sid].n_time_channels;
477 n_val_channels = this->rep.sigs.Sid2Info[sid].n_val_channels;
478 is_categ = &(this->rep.sigs.Sid2Info[sid].is_categorical_per_val_channel[0]);
479 }
480 }
481
482 void model_apply_verbose(bool flag) {
483 if ((model.verbosity > 0) ^ flag) {
484 model.verbosity = int(flag);
485
486 string full_log_format = "$timestamp\t$level\t$section\t%s";
487 global_logger.init_format(LOG_APP, full_log_format);
488 global_logger.init_format(LOG_DEF, full_log_format);
489 global_logger.init_format(LOG_MED_MODEL, full_log_format);
490 global_logger.init_format(LOG_MEDALGO, full_log_format);
491 MLOG("Activated logging, Version Info:\n%s\n", medial::get_git_version().c_str());
492 }
493 }
494
495 string model_version_info() const {
496 return model.version_info;
497 }
498
499 void get_model_signals_info(vector<string> &sigs,
500 unordered_map<string, vector<string>> &res_categ) const {
501 model.get_required_signal_names(sigs);
502 model.get_required_signal_categories(res_categ);
503 }
504
505 void get_explainer_params(Explainer_parameters &out) const {
506 out = explainer_params;
507 }
508
509 void get_explainer_output_options(vector<string> &opts) {
510 vector<const PostProcessor *> flat;
511 for (const PostProcessor *pp : model.post_processors) {
512 if (pp->processor_type == PostProcessorTypes::FTR_POSTPROCESS_MULTI)
513 {
514 const MultiPostProcessor *multi = static_cast<const MultiPostProcessor *>(pp);
515 for (const PostProcessor *m_pp : multi->post_processors)
516 flat.push_back(m_pp);
517 }
518 else
519 flat.push_back(pp);
520 }
521
522 for (const PostProcessor *pp : flat)
523 {
524 const ModelExplainer *explainer_m = dynamic_cast<const ModelExplainer *>(pp);
525 if (explainer_m != NULL) {
526 for (const string &grp : explainer_m->processing.groupNames)
527 opts.push_back(grp);
528 break;
529 }
530 }
531 }
532
533 void set_explainer_params(const string &params, const string &base_dir) {
534 explainer_params.base_dir = base_dir;
535 explainer_params.init_from_string(params);
536 }
537
538 void set_threshold_leaflet(const string &init_string, const string &base_dir) {
539 map<string, string> params;
540 if (MedSerialize::init_map_from_string(init_string, params) < 0)
541 MTHROW_AND_ERR("Error Init from String %s\n", init_string.c_str());
542 string bt_file_path = "";
543 map<string, string> rename_cohorts;
544 for (const auto &it : params)
545 {
546 if (it.first == "bootstrap_file_path")
547 bt_file_path = it.second;
548 else if (it.first == "rename_cohorts") {
549 vector<string> tokens;
550 boost::split(tokens, it.second, boost::is_any_of("#"));
551 for (const string &tk : tokens)
552 {
553 vector<string> src_target;
554 boost::split(src_target, tk, boost::is_any_of("|"));
555 if (src_target.size() != 2)
556 MTHROW_AND_ERR("Error expecting 2 tokens, recieved \"%s\"\n", tk.c_str());
557 mes_trim(src_target[1]);
558 mes_trim(src_target[1]);
559 rename_cohorts[src_target[0]] = src_target[1];
560 }
561 }
562 else if (it.first == "default_threshold") {
563 default_threshold = it.second;
564 mes_trim(default_threshold);
565 }
566 else
567 MTHROW_AND_ERR("Error unknown param %s\n", it.first.c_str());
568 }
569 if (bt_file_path.empty())
570 MTHROW_AND_ERR("Error must provide bootstrap_file_path in THRESHOLD_LEAFLET\n");
571
572 if (bt_file_path != "" && bt_file_path[0] != '/' && bt_file_path[0] != '\\' && !base_dir.empty())
573 bt_file_path = base_dir + path_sep() + bt_file_path;
574
575 if (default_threshold.empty())
576 MTHROW_AND_ERR("Error - must have default_threshold\n");
577
578 map<string, map<string, float>> mbr_before;
579 read_pivot_bootstrap_results(bt_file_path, mbr_before);
580
581 //commit rename:
582 for (auto &it : mbr_before)
583 {
584 string cohort = it.first;
585 if (rename_cohorts.find(cohort) != rename_cohorts.end())
586 cohort = rename_cohorts[cohort];
587 //Filter to take only "SCORE@" prefix - and SKIP missing values
588 map<string, float> &filt = mbr[cohort];
589 for (const auto &jt : it.second)
590 if (boost::starts_with(jt.first, "SCORE@") && boost::ends_with(jt.first, "_Mean") && jt.second != MED_MAT_MISSING_VALUE)
591 filt[jt.first.substr(6, jt.first.length() - 11)] = jt.second;
592 }
593
594 //Test default is OK:
595 string err_c;
596 fetch_threshold(default_threshold, err_c);
597 if (!err_c.empty()) {
598 vector<string> opts;
599 fetch_all_thresholds(opts);
600 for (const string & s : opts)
601 MLOG("Option: \"%s\"\n", s.c_str());
602 MTHROW_AND_ERR("Error default_threshold is invalid - please select one in format as COHORT$MEASURE_NUMERIC\n");
603 }
604 }
605
606 bool has_threshold_settings() const {
607 return !mbr.empty();
608 }
609
610 string get_default_threshold() const { return default_threshold; }
611
612 void fetch_all_thresholds(vector<string> &opts) const {
613 for (const auto &it : mbr)
614 {
615 for (const auto &jt : it.second)
616 {
617 string res = it.first + "$" + jt.first;
618 opts.push_back(res);
619 }
620 }
621 }
622
623 float fetch_threshold(const string &threshold, string &err_msg) const {
624 vector<string> tokens;
625 err_msg = "";
626 boost::split(tokens, threshold, boost::is_any_of("$"));
627 if (tokens.size() != 2) {
628 err_msg = "(" + to_string(AM_THRESHOLD_ERROR_NON_FATAL) + ")Error flag_threshold should contain $";
629 return MED_MAT_MISSING_VALUE;
630 }
631 mes_trim(tokens[0]);
632 mes_trim(tokens[1]);
633 if (mbr.find(tokens[0]) == mbr.end()) {
634 err_msg = "(" + to_string(AM_THRESHOLD_ERROR_NON_FATAL) + ")Error flag_threshold doesn't contain threshold settings for " + tokens[0];
635 return MED_MAT_MISSING_VALUE;
636 }
637 const map<string, float> &fnd = mbr.at(tokens[0]);
638 //Search numericly:
639 vector<string> meas_tokens;
640 boost::split(meas_tokens, tokens[1], boost::is_any_of("_"));
641 if (meas_tokens.size() != 2) {
642 err_msg = "(" + to_string(AM_THRESHOLD_ERROR_NON_FATAL) + ")Error flag_threshold doesn't should contain _ in the cutoff setting part";
643 return MED_MAT_MISSING_VALUE;
644 }
645 float num_val;
646 try {
647 num_val = stof(meas_tokens[1]);
648 }
649 catch (...) {
650 err_msg = "(" + to_string(AM_THRESHOLD_ERROR_NON_FATAL) + ")Error flag_threshold search cutoff isn't numeric";
651 return MED_MAT_MISSING_VALUE;
652 }
653
654 float res = MED_MAT_MISSING_VALUE;
655 for (const auto &jt : fnd)
656 {
657 string cand = jt.first;
658 vector<string> cand_tokens;
659 boost::split(cand_tokens, cand, boost::is_any_of("_"));
660 if (cand_tokens.size() != 2)
661 continue;
662 if (cand_tokens[0] != meas_tokens[0])
663 continue;
664 //Need to compare numericaly: cand_tokens[1] == meas_tokens[1]
665 float num_val_cmp;
666 try {
667 num_val_cmp = stof(cand_tokens[1]);
668 }
669 catch (...) {
670 continue;
671 }
672 if (abs(num_val_cmp - num_val) <= 1e-6) {
673 res = jt.second;
674 break; //found
675 }
676 }
677
678 if (res == MED_MAT_MISSING_VALUE)
679 err_msg = "(" + to_string(AM_THRESHOLD_ERROR_NON_FATAL) + ")Error flag_threshold doesn't contain threshold for " + tokens[1];
680 return res;
681 }
682};
683
#define LOG_DEF
general default section
Definition Logger.h:36
#define LOG_APP
user apps section
Definition Logger.h:34
#define MLOG(fmt,...)
MLOG() - use LOCAL_SECTION and LOCAL_LEVEL.
Definition Logger.h:145
MedModelStage
MedModel learn/apply stages.
Definition MedModel.h:22
@ MED_MDL_APPLY_FTR_PROCESSORS
Start from apply feature processors (already learned)
Definition MedModel.h:27
@ MED_MDL_APPLY_FTR_GENERATORS
Start from apply feature generators (already learned)
Definition MedModel.h:25
@ MED_MDL_END
All Done.
Definition MedModel.h:33
@ FTR_POSTPROCESS_MULTI
"multi_processor" or "multi" to create MultiPostProcessor
Definition PostProcessor.h:15
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:156
#define MEDSERIALIZE_SUPPORT(Type)
Definition SerializableObject.h:142
Definition AlgoMarkerInternal.h:64
int init(map< string, string > &mapper)
Virtual to init object from parsed fields.
Definition AlgoMarkerInternal.h:70
Definition AlgoMarkerInternal.h:86
bool use_perc
control if binning on absolute value or on percentage
Definition AlgoMarkerInternal.h:90
Explainer_description_config cfg
file to configure fetching signal to present
Definition AlgoMarkerInternal.h:91
unordered_set< string > ignore_groups_list
name list of groups to alwaya ignore
Definition AlgoMarkerInternal.h:92
int num_groups
control how much binning to present
Definition AlgoMarkerInternal.h:89
int total_max_reasons
if bigger than zero max limit for all reasons
Definition AlgoMarkerInternal.h:93
float threshold_percentage
percentage thershold if bigger than 0
Definition AlgoMarkerInternal.h:97
int init(map< string, string > &mapper)
Virtual to init object from parsed fields.
Definition AlgoMarkerInternal.h:103
float max_threshold
control max threshold
Definition AlgoMarkerInternal.h:88
int total_max_neg_reasons
if bigger than zero max limit for neg reasons
Definition AlgoMarkerInternal.h:95
float threshold_abs
absolute thershold if bigger than 0
Definition AlgoMarkerInternal.h:96
vector< string > static_features_info
config of information to fetch for every patient.
Definition AlgoMarkerInternal.h:98
int total_max_pos_reasons
if bigger than zero max limit for pos reasons
Definition AlgoMarkerInternal.h:94
Definition AlgoMarkerInternal.h:17
int max_count
limit of maximal last values
Definition AlgoMarkerInternal.h:21
int time_channel
time channel to filter
Definition AlgoMarkerInternal.h:23
int init(map< string, string > &mapper)
Virtual to init object from parsed fields.
Definition AlgoMarkerInternal.h:30
string signal_name
name of signal to fetch
Definition AlgoMarkerInternal.h:20
int val_channel
val channel to filter sets
Definition AlgoMarkerInternal.h:25
string contributer_group_name
name of explainer group
Definition AlgoMarkerInternal.h:19
int time_unit
time unit for max_time_window
Definition AlgoMarkerInternal.h:24
int max_time_window
limit on maximal time before prediction
Definition AlgoMarkerInternal.h:22
vector< string > sets
sets to filter categorical signal
Definition AlgoMarkerInternal.h:26
Definition AlgoMarkerInternal.h:155
void init_format(int section, const string &new_format)
sets log format.
Definition Logger.cpp:273
A model = repCleaner + featureGenerator + featureProcessor + MedPredictor.
Definition MedModel.h:56
Definition MedPidRepository.h:87
MedSamples represent a collection of samples per different id The data is conatined in a vector of ...
Definition MedSamples.h:131
static const int Days
days since 1900/01/01
Definition MedTime.h:28
int string_to_type(const string &str)
Convert string to type.
Definition MedTime.cpp:359
An abstract class API for explainer.
Definition ExplainWrapper.h:106
ExplainProcessings processing
processing of results, like groupings, COV
Definition ExplainWrapper.h:115
A wrapper for parallel call to post_processors group.
Definition PostProcessor.h:81
An Abstract PostProcessor class.
Definition PostProcessor.h:39
Definition SerializableObject.h:33
int init_from_string(string init_string)
Init from string.
Definition SerializableObject.cpp:112
string get_git_version()
general print to string woth format
Definition MedUtils.cpp:555