PerformanceMeasures.h

Go to the documentation of this file.
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 Sebastian Henschel
00008  * Copyright (C) 2008 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 
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 
00382     protected:
00384         void init_nolabels();
00385 
00394         template <class T> float64_t trapezoid_area(T x1, T x2, T y1, T y2);
00395 
00399         void create_sortedROC();
00400         
00404         void compute_ROC(float64_t** result);
00405 
00413         void compute_accuracy(
00414             float64_t** result, int32_t* num, int32_t* dim, bool do_error=false);
00415 
00420         void compute_PRC(float64_t** result);
00421 
00426         void compute_DET(float64_t** result);
00427 
00438         void compute_confusion_matrix(
00439             float64_t threshold,
00440             int32_t* tp, int32_t* fp, int32_t* fn, int32_t* tn);
00441 
00442     protected:
00444         CLabels* m_true_labels;
00446         CLabels* m_output;
00448         int32_t m_num_labels;
00449 
00451         int32_t m_all_true;
00453         int32_t m_all_false;
00454 
00457         int32_t* m_sortedROC;
00459         float64_t m_auROC;
00461         float64_t m_auPRC;
00463         float64_t m_auDET;
00464 
00465 };
00466 #endif /* __PERFORMANCEMEASURES_H_ */

SHOGUN Machine Learning Toolbox - Documentation