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
00031 class CPerformanceMeasures : public CSGObject
00032 {
00033 public:
00035 CPerformanceMeasures();
00036
00042 CPerformanceMeasures(CLabels* true_labels, CLabels* output);
00043
00044 virtual ~CPerformanceMeasures();
00045
00051 void init(CLabels* true_labels, CLabels* output);
00052
00058 inline bool set_true_labels(CLabels* true_labels)
00059 {
00060 m_true_labels=true_labels;
00061 SG_REF(true_labels);
00062 return true;
00063 }
00064
00069 inline CLabels* get_true_labels() const { return m_true_labels; }
00070
00076 inline bool set_output(CLabels* output)
00077 {
00078 m_output=output;
00079 SG_REF(output);
00080 return true;
00081 }
00082
00087 inline CLabels* get_output() const { return m_output; }
00088
00093 inline INT get_num_labels() const { return m_num_labels; }
00094
00107 void get_ROC(DREAL** result, INT* num, INT* dim);
00108
00115 inline DREAL get_auROC()
00116 {
00117 if (m_auROC==CMath::ALMOST_NEG_INFTY) {
00118 DREAL** roc=(DREAL**) malloc(sizeof(DREAL**));
00119 compute_ROC(roc);
00120 free(*roc);
00121 free(roc);
00122 }
00123 return m_auROC;
00124 }
00125
00132 inline DREAL get_aoROC()
00133 {
00134 return 1.0-get_auROC();
00135 }
00136
00149 void get_PRC(DREAL** result, INT* num, INT* dim);
00150
00157 inline DREAL get_auPRC()
00158 {
00159 if (m_auPRC==CMath::ALMOST_NEG_INFTY) {
00160 DREAL** prc=(DREAL**) malloc(sizeof(DREAL**));
00161 compute_PRC(prc);
00162 free(*prc);
00163 free(prc);
00164 }
00165 return m_auPRC;
00166 }
00167
00174 inline DREAL get_aoPRC()
00175 {
00176 return 1-get_auPRC();
00177 }
00178
00191 void get_DET(DREAL** result, INT* num, INT* dim);
00192
00199 inline DREAL get_auDET()
00200 {
00201 if (m_auDET==CMath::ALMOST_NEG_INFTY) {
00202 DREAL** det=(DREAL**) malloc(sizeof(DREAL**));
00203 compute_DET(det);
00204 free(*det);
00205 free(det);
00206 }
00207 return m_auDET;
00208 }
00209
00216 inline DREAL get_aoDET()
00217 {
00218 return 1-get_auDET();
00219 }
00220
00232 void get_all_accuracy(DREAL** result, INT* num, INT* dim);
00233
00240 DREAL get_accuracy(DREAL threshold=0);
00241
00253 void get_all_error(DREAL** result, INT* num, INT* dim);
00254
00263 inline DREAL get_error(DREAL threshold=0)
00264 {
00265 return 1.0-get_accuracy(threshold);
00266 }
00267
00279 void get_all_fmeasure(DREAL** result, INT* num, INT* dim);
00280
00285 DREAL get_fmeasure(DREAL threshold=0);
00286
00314 void get_all_CC(DREAL** result, INT* num, INT* dim);
00315
00320 DREAL get_CC(DREAL threshold=0);
00321
00339 void get_all_WRAcc(DREAL** result, INT* num, INT* dim);
00340
00345 DREAL get_WRAcc(DREAL threshold=0);
00346
00364 void get_all_BAL(DREAL** result, INT* num, INT* dim);
00365
00370 DREAL get_BAL(DREAL threshold=0);
00371
00372 protected:
00374 void init_nolabels();
00375
00384 template <class T> DREAL trapezoid_area(T x1, T x2, T y1, T y2);
00385
00389 void create_sortedROC();
00390
00394 void compute_ROC(DREAL** result);
00395
00403 void compute_accuracy(
00404 DREAL** result, INT* num, INT* dim, bool do_error=false);
00405
00410 void compute_PRC(DREAL** result);
00411
00416 void compute_DET(DREAL** result);
00417
00428 void compute_confusion_matrix(DREAL threshold, INT* tp, INT* fp, INT* fn, INT* tn);
00429
00430 protected:
00432 CLabels* m_true_labels;
00434 CLabels* m_output;
00436 INT m_num_labels;
00437
00439 INT m_all_true;
00441 INT m_all_false;
00442
00445 INT* m_sortedROC;
00447 DREAL m_auROC;
00449 DREAL m_auPRC;
00451 DREAL m_auDET;
00452
00453 };
00454 #endif