SHOGUN v0.9.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2008-2009 Sebastian Henschel 00008 * Copyright (C) 2008-2009 Friedrich Miescher Laboratory of Max-Planck-Society 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 00018 namespace shogun 00019 { 00020 class CLabels; 00021 00045 class CPerformanceMeasures : public CSGObject 00046 { 00047 public: 00049 CPerformanceMeasures(); 00050 00056 CPerformanceMeasures(CLabels* true_labels, CLabels* output); 00057 00058 virtual ~CPerformanceMeasures(); 00059 00065 bool set_true_labels(CLabels* true_labels); 00066 00071 inline CLabels* get_true_labels() const 00072 { 00073 SG_REF(m_true_labels); 00074 return m_true_labels; 00075 } 00076 00082 bool set_output(CLabels* output); 00083 00088 inline CLabels* get_output() const 00089 { 00090 SG_REF(m_output); 00091 return m_output; 00092 } 00093 00098 inline int32_t get_num_labels() const { return m_num_labels; } 00099 00112 void get_ROC(float64_t** result, int32_t* num, int32_t* dim); 00113 00120 inline float64_t get_auROC() 00121 { 00122 if (m_auROC==CMath::ALMOST_NEG_INFTY) 00123 { 00124 float64_t** roc=(float64_t**) malloc(sizeof(float64_t**)); 00125 compute_ROC(roc); 00126 free(*roc); 00127 free(roc); 00128 } 00129 return m_auROC; 00130 } 00131 00138 inline float64_t get_aoROC() 00139 { 00140 return 1.0-get_auROC(); 00141 } 00142 00155 void get_PRC(float64_t** result, int32_t* num, int32_t* dim); 00156 00163 inline float64_t get_auPRC() 00164 { 00165 if (m_auPRC==CMath::ALMOST_NEG_INFTY) { 00166 float64_t** prc=(float64_t**) malloc(sizeof(float64_t**)); 00167 compute_PRC(prc); 00168 free(*prc); 00169 free(prc); 00170 } 00171 return m_auPRC; 00172 } 00173 00180 inline float64_t get_aoPRC() 00181 { 00182 return 1-get_auPRC(); 00183 } 00184 00197 void get_DET(float64_t** result, int32_t* num, int32_t* dim); 00198 00205 inline float64_t get_auDET() 00206 { 00207 if (m_auDET==CMath::ALMOST_NEG_INFTY) 00208 { 00209 float64_t** det=(float64_t**) malloc(sizeof(float64_t**)); 00210 compute_DET(det); 00211 free(*det); 00212 free(det); 00213 } 00214 return m_auDET; 00215 } 00216 00223 inline float64_t get_aoDET() 00224 { 00225 return 1-get_auDET(); 00226 } 00227 00239 void get_all_accuracy(float64_t** result, int32_t* num, int32_t* dim); 00240 00247 float64_t get_accuracy(float64_t threshold=0); 00248 00260 void get_all_error(float64_t** result, int32_t* num, int32_t* dim); 00261 00270 inline float64_t get_error(float64_t threshold=0) 00271 { 00272 return 1.0-get_accuracy(threshold); 00273 } 00274 00286 void get_all_fmeasure(float64_t** result, int32_t* num, int32_t* dim); 00287 00292 float64_t get_fmeasure(float64_t threshold=0); 00293 00321 void get_all_CC(float64_t** result, int32_t* num, int32_t* dim); 00322 00327 float64_t get_CC(float64_t threshold=0); 00328 00346 void get_all_WRAcc(float64_t** result, int32_t* num, int32_t* dim); 00347 00352 float64_t get_WRAcc(float64_t threshold=0); 00353 00371 void get_all_BAL(float64_t** result, int32_t* num, int32_t* dim); 00372 00377 float64_t get_BAL(float64_t threshold=0); 00378 00383 inline virtual const char* get_name() const { return "PerformanceMeasures"; } 00384 00385 protected: 00387 void init_nolabels(); 00388 00397 float64_t trapezoid_area(float64_t x1, float64_t x2, float64_t y1, float64_t y2); 00398 00402 void create_sortedROC(); 00403 00407 void compute_ROC(float64_t** result); 00408 00416 void compute_accuracy( 00417 float64_t** result, int32_t* num, int32_t* dim, bool do_error=false); 00418 00423 void compute_PRC(float64_t** result); 00424 00429 void compute_DET(float64_t** result); 00430 00441 void compute_confusion_matrix( 00442 float64_t threshold, 00443 int32_t* tp, int32_t* fp, int32_t* fn, int32_t* tn); 00444 00445 protected: 00447 CLabels* m_true_labels; 00449 CLabels* m_output; 00451 int32_t m_num_labels; 00452 00454 int32_t m_all_true; 00456 int32_t m_all_false; 00457 00460 int32_t* m_sortedROC; 00462 float64_t m_auROC; 00464 float64_t m_auPRC; 00466 float64_t m_auDET; 00467 }; 00468 } // namespace shogun 00469 #endif /* __PERFORMANCEMEASURES_H_ */