openModeller  Version 1.5.0
RocCurve.hh
Go to the documentation of this file.
1 
26 #ifndef _ROCCURVEHH_
27 #define _ROCCURVEHH_
28 
29 #include <openmodeller/om_defs.hh>
31 
32 #include <openmodeller/Model.hh>
33 
36 #include <openmodeller/Sampler.hh>
37 
38 #include <map>
39 
40 #define ROC_DEFAULT_RESOLUTION 15
41 #define ROC_DEFAULT_BACKGROUND_POINTS 10000
42 
46 class dllexp RocCurve
47 {
48 public:
52  RocCurve();
53 
57  ~RocCurve();
58 
66  void initialize( int resolution=ROC_DEFAULT_RESOLUTION );
67 
75  void initialize( int resolution, int num_background_points );
76 
86  void initialize( int resolution, bool use_absences_as_background );
87 
91  void reset();
92 
100  void calculate( const Model& model, const SamplerPtr& sampler );
101 
106  int numPoints() const { return _data.size(); }
107 
115  double getX( int point_index ) const { return _data[point_index][0]; }
116 
123  double getY( int point_index ) const { return _data[point_index][1]; }
124 
129  double getTotalArea();
130 
139  double getPartialAreaRatio( double e=1.0 );
140 
144  bool ready() const { return _ready; }
145 
149  ConfigurationPtr getConfiguration() const;
150 
151 private:
152 
156  struct VectorCompare {
157 
158  bool operator () ( const std::vector<Scalar> &a, const std::vector<Scalar> &b ) const {
159 
160  if ( a[0] != b[0] ) {
161 
162  return a[0] < b[0]; // Compare 1 - specificity.
163  }
164  else {
165 
166  return a[1] < b[1]; // Compare sensitivity (1 - specificity values are equal).
167  }
168  }
169  };
170 
176  void _loadPredictions( const Model& model, const SamplerPtr& sampler );
177 
181  void _calculateGraphPoints();
182 
186  bool _calculateTotalArea();
187 
188  std::vector<int> _category; // 0=absence, 1=presence
189  std::vector<Scalar> _prediction; // associated probabilities
190 
191  std::vector< std::vector<Scalar> > _data; // Main data structure to store all points
192 
193  int _resolution; // Number of points on the curve
194 
195  int _approach; // Approach to be used: 0=undefined, 1=traditional (presence x absence), 2=proportional area
196 
197  int _num_background_points; // Number of background points to be generated when there are no absences. Only for proportional area approach.
198  bool _use_absences_as_background; // Indicates if absence points should be used as background points. Only for proportional area approach.
199 
200  int _true_negatives; // Number of true negatives (binarized)
201  int _true_positives; // Number of true positives (binarized)
202 
203  double _auc; // Area under the curve. Need to store this to avoid recalculating in serialization.
204 
205  std::map<double, double> _ratios; // Ratios calculated via getPartialAreaRatio (max omission <=> ratio). Ratios are stored here to be used during serialization.
206 
207  std::vector<Scalar> _thresholds; // Thresholds in ascending order
208 
209  std::vector<Scalar> _proportions; // Proportional area for each point
210 
211  bool _ready;
212 };
213 
214 #endif
std::vector< Scalar > _thresholds
Definition: RocCurve.hh:207
std::vector< std::vector< Scalar > > _data
Definition: RocCurve.hh:191
std::vector< Scalar > _proportions
Definition: RocCurve.hh:209
int _true_positives
Definition: RocCurve.hh:201
int _num_background_points
Definition: RocCurve.hh:197
int numPoints() const
Definition: RocCurve.hh:106
std::vector< Scalar > _prediction
Definition: RocCurve.hh:189
int _true_negatives
Definition: RocCurve.hh:200
bool ready() const
Definition: RocCurve.hh:144
int _approach
Definition: RocCurve.hh:195
bool _ready
Definition: RocCurve.hh:211
double getX(int point_index) const
Definition: RocCurve.hh:115
int _resolution
Definition: RocCurve.hh:193
bool _use_absences_as_background
Definition: RocCurve.hh:198
#define ROC_DEFAULT_RESOLUTION
Definition: RocCurve.hh:40
double getY(int point_index) const
Definition: RocCurve.hh:123
double _auc
Definition: RocCurve.hh:203
std::map< double, double > _ratios
Definition: RocCurve.hh:205
std::vector< int > _category
Definition: RocCurve.hh:188