Medial Code Documentation
Loading...
Searching...
No Matches
FairnessPostProcessor.h
1#ifndef __FAIRNESS_POSTPROCESSOR_H__
2#define __FAIRNESS_POSTPROCESSOR_H__
3
4#include "PostProcessor.h"
6
7enum Cutoff_Type {
8 Score = 0,
9 PR = 1,
10 Sens = 2
11};
12
13extern unordered_map<string, int> map_target_type;
14enum Fairness_Target_Type {
15 SENS = 0,
16 SPEC = 1
17};
18
21public:
22 Cutoff_Type type;
23 float value;
24
25 void set_type(const string &t);
26
27 ADD_CLASS_NAME(Cutoff_Constraint)
29};
30
35private:
36 unordered_map<float, vector<float>> group_to_score_cutoffs_ranges;
37 unordered_map<float, vector<float>> group_to_factors;
38 unordered_map<float, vector<float>> group_to_bias;
39 bool feature_gen_init = false;
40public:
41 string feature_name;
42 string model_json;
43 float reference_group_val = MED_MAT_MISSING_VALUE;
44 Fairness_Target_Type fairness_target_type;
45 vector<Cutoff_Constraint> constraints;
46 double resulotion = 0.1;
47 double allow_distance_score = 1.0;
48 double allow_distance_target = 5.0;
50 int score_bin_count = 5000;
51 float score_resulotion = 0;
52
56
59 void init_post_processor(MedModel& mdl) { p_rep = mdl.p_rep; }
60
61 void parse_constrains(const string &s);
62
63 void get_input_fields(vector<Effected_Field> &fields) const;
64 void get_output_fields(vector<Effected_Field> &fields) const;
65
67 int init(map<string, string> &mapper);
68
70 void Learn(const MedFeatures &matrix);
71 void Apply(MedFeatures &matrix);
72
73 void dprint(const string &pref) const;
74
75 ADD_CLASS_NAME(FairnessPostProcessor)
78 group_to_score_cutoffs_ranges, group_to_factors, group_to_bias, allow_distance_cutoff_constraint,
80};
81
84
85#endif
Logger.h - allowing logs with more control.
@ FTR_POSTPROCESS_FAIRNESS
"fairness_adjust" to adjust model calibrated predictions according to priors. Creates ProbAdjustPostP...
Definition PostProcessor.h:26
#define ADD_SERIALIZATION_FUNCS(...)
Definition SerializableObject.h:122
#define MEDSERIALIZE_SUPPORT(Type)
Definition SerializableObject.h:108
class that hold constrain that translate on reference group into raw score cutoff to measure fainess
Definition FairnessPostProcessor.h:20
float value
the value
Definition FairnessPostProcessor.h:23
Cutoff_Type type
constraint type
Definition FairnessPostProcessor.h:22
A post-processor to adjust probability to fairness between groups.
Definition FairnessPostProcessor.h:34
MedPidRepository * p_rep
required for building model for generating model (set by process)
Definition FairnessPostProcessor.h:53
int score_bin_count
how much bins for score. 0 means no binning
Definition FairnessPostProcessor.h:50
float score_resulotion
if >0 will apply score resulotion for speedup
Definition FairnessPostProcessor.h:51
float reference_group_val
the value for the feature used as refernce group for fairness
Definition FairnessPostProcessor.h:43
void parse_constrains(const string &s)
parses the constrains
Definition FairnessPostProcessor.cpp:27
MedModel group_feature_gen_model
model for generating features for priors (set in learn)
Definition FairnessPostProcessor.h:54
double allow_distance_cutoff_constraint
max distance allow between constraint
Definition FairnessPostProcessor.h:49
double allow_distance_target
max distance allow between target
Definition FairnessPostProcessor.h:48
vector< Cutoff_Constraint > constraints
list of constraints cutoffs. Init with comma seperated list for each constraint. The type is prefix w...
Definition FairnessPostProcessor.h:45
string feature_name
feautre name to search in matrix created by model_json to generate group for fairness
Definition FairnessPostProcessor.h:41
void Learn(const MedFeatures &matrix)
Learns from predictor and train_matrix (PostProcessor API)
Definition FairnessPostProcessor.cpp:227
int init(map< string, string > &mapper)
Global init for general args in all explainers.
Definition FairnessPostProcessor.cpp:48
double allow_distance_score
max distance allow between score
Definition FairnessPostProcessor.h:47
double resulotion
resulotion for target matching. effect speed/accuracy
Definition FairnessPostProcessor.h:46
string model_json
model json path - important for learn
Definition FairnessPostProcessor.h:42
string resolved_name
resolved feature name (value is set after learn)
Definition FairnessPostProcessor.h:55
void get_input_fields(vector< Effected_Field > &fields) const
List of fields that are used by this post_processor.
Definition FairnessPostProcessor.cpp:95
void get_output_fields(vector< Effected_Field > &fields) const
List of fields that are being effected by this post_processor.
Definition FairnessPostProcessor.cpp:98
Fairness_Target_Type fairness_target_type
fairness target - SENS of SPEC
Definition FairnessPostProcessor.h:44
A class for holding features data as a virtual matrix
Definition MedFeatures.h:47
A model = repCleaner + featureGenerator + featureProcessor + MedPredictor.
Definition MedModel.h:56
MedPidRepository * p_rep
not serialized. stores pointer to rep used in Learn or Apply after call.
Definition MedModel.h:302
Definition MedPidRepository.h:87
An Abstract PostProcessor class.
Definition PostProcessor.h:39
Definition SerializableObject.h:32