1 | #ifndef _theplu_yat_statistics_auc_ |
---|
2 | #define _theplu_yat_statistics_auc_ |
---|
3 | |
---|
4 | // $Id: AUC.h 1487 2008-09-10 08:41:36Z jari $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson |
---|
9 | Copyright (C) 2008 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 Class calculating Area Under ROC Curve |
---|
45 | /// |
---|
46 | class AUC : public Score |
---|
47 | { |
---|
48 | |
---|
49 | public: |
---|
50 | /// |
---|
51 | /// \brief Defaul Constructor |
---|
52 | /// \param absolute if true max(AUC, 1-AUC) is used |
---|
53 | /// |
---|
54 | AUC(bool absolute=true); |
---|
55 | |
---|
56 | /// Function taking \a value, \a target (+1 or -1) and vector |
---|
57 | /// defining what samples to use. The score is equivalent to |
---|
58 | /// Mann-Whitney statistics. |
---|
59 | /// @return the area under the ROC curve. If the area is less |
---|
60 | /// than 0.5 and absolute=true, 1-area is returned. Complexity is |
---|
61 | /// \f$ N\log N \f$ where \f$ N \f$ is number of samples. |
---|
62 | /// |
---|
63 | double score(const classifier::Target& target, |
---|
64 | const utility::VectorBase& value) const; |
---|
65 | |
---|
66 | /** |
---|
67 | Function taking values, target, weight and a vector defining |
---|
68 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
69 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
70 | over all pairs where value+ is larger than value-. The |
---|
71 | denominator goes over all pairs. If target is equal to 1, |
---|
72 | sample belonges to class + otherwise sample belongs to class |
---|
73 | -. @return wheighted version of area under the ROC curve. If |
---|
74 | the area is less than 0.5 and absolute=true, 1-area is |
---|
75 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
76 | of samples. |
---|
77 | */ |
---|
78 | double score(const classifier::Target& target, |
---|
79 | const classifier::DataLookupWeighted1D& value) const; |
---|
80 | |
---|
81 | /** |
---|
82 | Function taking values, target, weight and a vector defining |
---|
83 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
84 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
85 | over all pairs where value+ is larger than value-. The |
---|
86 | denominator goes over all pairs. If target is equal to 1, |
---|
87 | sample belonges to class + otherwise sample belongs to class |
---|
88 | -. @return wheighted version of area under the ROC curve. If |
---|
89 | the area is less than 0.5 and absolute=true, 1-area is |
---|
90 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
91 | of samples. |
---|
92 | */ |
---|
93 | double score(const classifier::Target& target, |
---|
94 | const utility::VectorBase& value, |
---|
95 | const utility::VectorBase& weight) const; |
---|
96 | |
---|
97 | private: |
---|
98 | friend class ROC; |
---|
99 | |
---|
100 | typedef std::multimap<double, std::pair<bool, double> > MultiMap; |
---|
101 | double score(const MultiMap&) const; |
---|
102 | |
---|
103 | }; |
---|
104 | |
---|
105 | }}} // of namespace statistics, yat, and theplu |
---|
106 | |
---|
107 | #endif |
---|