1 | #ifndef _theplu_yat_statistics_auc_ |
---|
2 | #define _theplu_yat_statistics_auc_ |
---|
3 | |
---|
4 | // $Id: AUC.h 2992 2013-03-03 05:03:44Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
9 | Copyright (C) 2011 Peter Johansson |
---|
10 | |
---|
11 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
12 | |
---|
13 | The yat library is free software; you can redistribute it and/or |
---|
14 | modify it under the terms of the GNU General Public License as |
---|
15 | published by the Free Software Foundation; either version 3 of the |
---|
16 | License, or (at your option) any later version. |
---|
17 | |
---|
18 | The yat library is distributed in the hope that it will be useful, |
---|
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | General Public License for more details. |
---|
22 | |
---|
23 | You should have received a copy of the GNU General Public License |
---|
24 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
25 | */ |
---|
26 | |
---|
27 | #include "Score.h" |
---|
28 | #include "yat/utility/stl_utility.h" |
---|
29 | |
---|
30 | #include <utility> |
---|
31 | #include <map> |
---|
32 | |
---|
33 | namespace theplu { |
---|
34 | namespace yat { |
---|
35 | namespace classifier { |
---|
36 | class Target; |
---|
37 | } |
---|
38 | namespace utility { |
---|
39 | class VectorBase; |
---|
40 | } |
---|
41 | namespace statistics { |
---|
42 | |
---|
43 | /** |
---|
44 | \brief Area Under ROC Curve |
---|
45 | |
---|
46 | Class calculates area under curve from values, Target, and |
---|
47 | possibly weights. If weights are left out, unity weights are |
---|
48 | assumed. The area under curve is defined as |
---|
49 | \f[ |
---|
50 | \frac{\sum_{i,j} I(x_i^+-x_j^-) w_i^+w_j^-} {\sum_{i,j} |
---|
51 | w_i^+w_j^-} \f] |
---|
52 | where |
---|
53 | \f{eqnarray*}{ |
---|
54 | &0; &x<0 \\ |
---|
55 | I(x) = &0.5; &x=0 \\ |
---|
56 | &1; &x>0 |
---|
57 | \f} |
---|
58 | |
---|
59 | Complexity of calculating the AUC is \f$ N \log N \f$. |
---|
60 | */ |
---|
61 | class AUC : public Score |
---|
62 | { |
---|
63 | |
---|
64 | public: |
---|
65 | /// |
---|
66 | /// \brief Default Constructor |
---|
67 | /// \param absolute if true max(AUC, 1-AUC) is used |
---|
68 | /// |
---|
69 | AUC(bool absolute=true); |
---|
70 | |
---|
71 | /** |
---|
72 | \return area under the ROC curve. |
---|
73 | */ |
---|
74 | double score(const classifier::Target& target, |
---|
75 | const utility::VectorBase& value) const; |
---|
76 | |
---|
77 | /** |
---|
78 | \return area under the ROC curve. |
---|
79 | */ |
---|
80 | double score(const classifier::Target& target, |
---|
81 | const classifier::DataLookupWeighted1D& value) const; |
---|
82 | |
---|
83 | /** |
---|
84 | \return area under the ROC curve. |
---|
85 | */ |
---|
86 | double score(const classifier::Target& target, |
---|
87 | const utility::VectorBase& value, |
---|
88 | const utility::VectorBase& weight) const; |
---|
89 | |
---|
90 | private: |
---|
91 | friend class ROC; |
---|
92 | |
---|
93 | typedef std::multimap<double, std::pair<bool, double> > MultiMap; |
---|
94 | double score(const MultiMap&) const; |
---|
95 | }; |
---|
96 | |
---|
97 | }}} // of namespace statistics, yat, and theplu |
---|
98 | |
---|
99 | #endif |
---|