PerformanceMeasures.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __PERFORMANCEMEASURES_H_
00012 #define __PERFORMANCEMEASURES_H_
00013
00014 #include "base/SGObject.h"
00015 #include "features/Labels.h"
00016 #include "lib/DynamicArray.h"
00017
00041 class CPerformanceMeasures : public CSGObject
00042 {
00043 public:
00045 CPerformanceMeasures();
00046
00052 CPerformanceMeasures(CLabels* true_labels, CLabels* output);
00053
00054 virtual ~CPerformanceMeasures();
00055
00061 void init(CLabels* true_labels, CLabels* output);
00062
00068 inline bool set_true_labels(CLabels* true_labels)
00069 {
00070 m_true_labels=true_labels;
00071 SG_REF(true_labels);
00072 return true;
00073 }
00074
00079 inline CLabels* get_true_labels() const { return m_true_labels; }
00080
00086 inline bool set_output(CLabels* output)
00087 {
00088 m_output=output;
00089 SG_REF(output);
00090 return true;
00091 }
00092
00097 inline CLabels* get_output() const { return m_output; }
00098
00103 inline int32_t get_num_labels() const { return m_num_labels; }
00104
00117 void get_ROC(float64_t** result, int32_t* num, int32_t* dim);
00118
00125 inline float64_t get_auROC()
00126 {
00127 if (m_auROC==CMath::ALMOST_NEG_INFTY) {
00128 float64_t** roc=(float64_t**) malloc(sizeof(float64_t**));
00129 compute_ROC(roc);
00130 free(*roc);
00131 free(roc);
00132 }
00133 return m_auROC;
00134 }
00135
00142 inline float64_t get_aoROC()
00143 {
00144 return 1.0-get_auROC();
00145 }
00146
00159 void get_PRC(float64_t** result, int32_t* num, int32_t* dim);
00160
00167 inline float64_t get_auPRC()
00168 {
00169 if (m_auPRC==CMath::ALMOST_NEG_INFTY) {
00170 float64_t** prc=(float64_t**) malloc(sizeof(float64_t**));
00171 compute_PRC(prc);
00172 free(*prc);
00173 free(prc);
00174 }
00175 return m_auPRC;
00176 }
00177
00184 inline float64_t get_aoPRC()
00185 {
00186 return 1-get_auPRC();
00187 }
00188
00201 void get_DET(float64_t** result, int32_t* num, int32_t* dim);
00202
00209 inline float64_t get_auDET()
00210 {
00211 if (m_auDET==CMath::ALMOST_NEG_INFTY) {
00212 float64_t** det=(float64_t**) malloc(sizeof(float64_t**));
00213 compute_DET(det);
00214 free(*det);
00215 free(det);
00216 }
00217 return m_auDET;
00218 }
00219
00226 inline float64_t get_aoDET()
00227 {
00228 return 1-get_auDET();
00229 }
00230
00242 void get_all_accuracy(float64_t** result, int32_t* num, int32_t* dim);
00243
00250 float64_t get_accuracy(float64_t threshold=0);
00251
00263 void get_all_error(float64_t** result, int32_t* num, int32_t* dim);
00264
00273 inline float64_t get_error(float64_t threshold=0)
00274 {
00275 return 1.0-get_accuracy(threshold);
00276 }
00277
00289 void get_all_fmeasure(float64_t** result, int32_t* num, int32_t* dim);
00290
00295 float64_t get_fmeasure(float64_t threshold=0);
00296
00324 void get_all_CC(float64_t** result, int32_t* num, int32_t* dim);
00325
00330 float64_t get_CC(float64_t threshold=0);
00331
00349 void get_all_WRAcc(float64_t** result, int32_t* num, int32_t* dim);
00350
00355 float64_t get_WRAcc(float64_t threshold=0);
00356
00374 void get_all_BAL(float64_t** result, int32_t* num, int32_t* dim);
00375
00380 float64_t get_BAL(float64_t threshold=0);
00381
00386 inline virtual const char* get_name() const { return "PerformanceMeasures"; }
00387
00388 protected:
00390 void init_nolabels();
00391
00400 float64_t trapezoid_area(float64_t x1, float64_t x2, float64_t y1, float64_t y2);
00401
00405 void create_sortedROC();
00406
00410 void compute_ROC(float64_t** result);
00411
00419 void compute_accuracy(
00420 float64_t** result, int32_t* num, int32_t* dim, bool do_error=false);
00421
00426 void compute_PRC(float64_t** result);
00427
00432 void compute_DET(float64_t** result);
00433
00444 void compute_confusion_matrix(
00445 float64_t threshold,
00446 int32_t* tp, int32_t* fp, int32_t* fn, int32_t* tn);
00447
00448 protected:
00450 CLabels* m_true_labels;
00452 CLabels* m_output;
00454 int32_t m_num_labels;
00455
00457 int32_t m_all_true;
00459 int32_t m_all_false;
00460
00463 int32_t* m_sortedROC;
00465 float64_t m_auROC;
00467 float64_t m_auPRC;
00469 float64_t m_auDET;
00470
00471 };
00472 #endif