Medial Code Documentation
Loading...
Searching...
No Matches
MedPerformance.h
1//
2// MedPerformance used for analyzing performance
3//
4
5#ifndef _MED_PERFORMANCE_T_H_
6#define _MED_PERFORMANCE_T_H_
7
8#include <stdlib.h>
9#include <stdarg.h>
10#include <stdio.h>
11
12#include <assert.h>
13#include <math.h>
14
15#include <vector>
16#include <map>
17#include <string>
18#include <algorithm>
19
20#include <MedProcessTools/MedProcessTools/MedSamples.h>
21#include <MedProcessTools/MedProcessTools/MedFeatures.h>
22#include <MedUtils/MedUtils/MedGenUtils.h>
23#include <string.h>
24
25#define MED_CLEANER_MAX_Z 15
26#define MED_CLEANER_EPSILON 0.0001
27
28using namespace std ;
29
30// Performance class : Calculation and Comparison of performance parameters.
31enum PerformanceCompareMode {
32 PRF_COMPARE_FULL = 1,
33 PRF_COMPARE_ALL = 2,
34 PRF_COMPARE_SPLITS = 3,
35 PRF_COMPARE_FULL_AND_PART_SPLITS = 4,
36 PRF_COMPARE_LAST = 5,
37} ;
38
40public:
41 string setParam ;
42 string queriedParam ;
43 float setValue ;
44
45 Measurement(const string& qParam, const string& sParam, float sValue) ; // Look for value of qParams when sParam=sValue
46 Measurement(const string& qParam, float sValue) ; // Look at value of qParam parameterized by sValue (e.g. "auc",0.2 for partial AUC)
47 Measurement(const string& qParam) ; // Look at value of qParam (e.g. "auc")
48 Measurement() ;
49
50 inline bool operator<(const Measurement& otherMeasuemrent) const {
51 return ((queriedParam < otherMeasuemrent.queriedParam) ||
52 (queriedParam == otherMeasuemrent.queriedParam && setValue < otherMeasuemrent.setValue) ||
53 (queriedParam == otherMeasuemrent.queriedParam && setValue == otherMeasuemrent.setValue && setParam < otherMeasuemrent.setParam)) ;
54
55 }
56
57 static void get_from_name(string& fileName, Measurement& msrs);
58 static void read_from_file(string& fileName, vector<Measurement>& msrs);
59 string name();
60} ;
61
63public:
64
65 // Prediction data (first elemnt = full data; next elements = splits)
66 vector<vector<pair<float, float> > > preds ;
67
68 // counters
69 vector<int> npos,nneg ;
70 vector<vector<int> > tps,fps ;
71
72 // Performance
73 vector<map<string, vector<float> > > PerformanceValues ;
74 map<Measurement,vector<float> > MeasurementValues ;
75
76 // Comparison
77 Measurement comparePoint ;
78 PerformanceCompareMode compareMode ;
79 float partialCompareRatio ;
80
81 // Helper - locations of queried PerformancePointer
82 vector<map<pair<string,float> , pair<int,int> > > PerformancePointers ;
83 map<string,int> compareDirections ;
84
85 // Init
86 void init() ;
87
88 // Load
89 void _load(vector<pair<float,float> >& in_preds) ;
90 void _load(vector<vector<pair<float,float> > >& in_split_preds) ;
91 void _load(MedSamples& inSamples);
92 void _load(MedFeatures& ftrs);
93 void post_load();
94 template <typename T> void load(T& object) ;
95 template <typename T, typename S> void load(T *preds, S *labels, int n) ;
96
97 // Helper functions for loading
98 void SplitsToComplete() ;
99 void ShuffleSort() ;
100 void Count() ;
101 void getPerformanceValues() ;
102
103 // Constructors
105 template <typename T> MedClassifierPerformance(T& object) ;
106 template <typename T, typename S> MedClassifierPerformance(T *preds, S *labels, int n) ;
107
108 // Queries
109 vector<float> operator() (Measurement& inMeasurement) ;
110 // Parameter at point determined by another parameters (e.g. PPV at Specificity = 0.99 is GetPerformanceParam("PPV","Spec",0.99,outPPV). setParams = (Score,Sens,Spec), queriedParams = (Score,Sens,Spec,PPV,NPV,OR)
111 int GetPerformanceParam(const string& setParam, const string& queriedParam, float setValue) ;
112 int GetPerformanceParam(Measurement& inMeasurement) ;
113 // General performance parameter, with optional value (e.g. AUC = GetPerformanceParam("AUC",outAuc) or GetPerformanceParam("AUC",1.0,outAUC). Partial AUC = GetPerformanceParam("AUC",0.2,partAUC)
114 int GetPerformanceParam(const string& queriedParam, float setValue) ;
115 int GetPerformanceParam(const string& queriedParam) ;
116 // Performance Graph
117 int GetPrformanceGraph(const string& xParam, const string& yParam, vector<vector<float> >& x, vector<vector<float> >& y) ;
118
119 // Comparison
120 int compare(MedClassifierPerformance& other) ;
121
122 // Helpers for queries
123 int getPerformancePointer(pair<string,float>& set, int index) ;
124 int getPointer(const string& param, float value, int index, int direction) ;
125 void getAUC(float maxFPR, vector<float>& qValues) ;
126 float getAUC(float maxFPR, int index) ;
127
128 int getPerformanceValues(pair<string,float>& set, const string &queriedParam, int index, vector<float>& queriedValues) ;
129
130private:
131 struct _PredsCompare {
132 bool operator()(const pair<float, float>& left, const pair<float, float>& right) {
133 return (left.first > right.first) ;
134 } ;
135 } ;
136} ;
137
138#include "MedPerformance_imp.h"
139
140#endif
Definition MedPerformance.h:39
Definition MedPerformance.h:62
A class for holding features data as a virtual matrix
Definition MedFeatures.h:47
MedSamples represent a collection of samples per different id The data is conatined in a vector of ...
Definition MedSamples.h:129
Copyright 2015-2023 by XGBoost Contributors.
Definition StdDeque.h:58