1 | #ifndef _theplu_yat_statistics_auc_ |
---|
2 | #define _theplu_yat_statistics_auc_ |
---|
3 | |
---|
4 | // $Id: AUC.h 865 2007-09-10 19:41:04Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2004 Peter Johansson |
---|
8 | Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson |
---|
9 | Copyright (C) 2007 Peter Johansson |
---|
10 | |
---|
11 | This file is part of the yat library, http://trac.thep.lu.se/trac/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 2 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 this program; if not, write to the Free Software |
---|
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
26 | 02111-1307, USA. |
---|
27 | */ |
---|
28 | |
---|
29 | #include "Score.h" |
---|
30 | #include "yat/utility/stl_utility.h" |
---|
31 | |
---|
32 | #include <utility> |
---|
33 | #include <map> |
---|
34 | |
---|
35 | namespace theplu { |
---|
36 | namespace yat { |
---|
37 | namespace classifier { |
---|
38 | class Target; |
---|
39 | } |
---|
40 | namespace utility { |
---|
41 | class vector; |
---|
42 | } |
---|
43 | namespace statistics { |
---|
44 | |
---|
45 | /// |
---|
46 | /// @brief Class calculating Area Under ROC Curve |
---|
47 | /// |
---|
48 | class AUC : public Score |
---|
49 | { |
---|
50 | |
---|
51 | public: |
---|
52 | /// |
---|
53 | /// |
---|
54 | /// |
---|
55 | AUC(bool absolute=true); |
---|
56 | |
---|
57 | /// Function taking \a value, \a target (+1 or -1) and vector |
---|
58 | /// defining what samples to use. The score is equivalent to |
---|
59 | /// Mann-Whitney statistics. |
---|
60 | /// @return the area under the ROC curve. If the area is less |
---|
61 | /// than 0.5 and absolute=true, 1-area is returned. Complexity is |
---|
62 | /// \f$ N\log N \f$ where \f$ N \f$ is number of samples. |
---|
63 | /// |
---|
64 | double score(const classifier::Target& target, |
---|
65 | const utility::vector& value) const; |
---|
66 | |
---|
67 | /** |
---|
68 | Function taking values, target, weight and a vector defining |
---|
69 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
70 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
71 | over all pairs where value+ is larger than value-. The |
---|
72 | denominator goes over all pairs. If target is equal to 1, |
---|
73 | sample belonges to class + otherwise sample belongs to class |
---|
74 | -. @return wheighted version of area under the ROC curve. If |
---|
75 | the area is less than 0.5 and absolute=true, 1-area is |
---|
76 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
77 | of samples. |
---|
78 | */ |
---|
79 | double score(const classifier::Target& target, |
---|
80 | const classifier::DataLookupWeighted1D& value) const; |
---|
81 | |
---|
82 | /** |
---|
83 | Function taking values, target, weight and a vector defining |
---|
84 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
85 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
86 | over all pairs where value+ is larger than value-. The |
---|
87 | denominator goes over all pairs. If target is equal to 1, |
---|
88 | sample belonges to class + otherwise sample belongs to class |
---|
89 | -. @return wheighted version of area under the ROC curve. If |
---|
90 | the area is less than 0.5 and absolute=true, 1-area is |
---|
91 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
92 | of samples. |
---|
93 | */ |
---|
94 | double score(const classifier::Target& target, |
---|
95 | const utility::vector& value, |
---|
96 | const utility::vector& weight) const; |
---|
97 | |
---|
98 | private: |
---|
99 | friend class ROC; |
---|
100 | |
---|
101 | typedef std::multimap<double, std::pair<bool, double> > MultiMap; |
---|
102 | double score(const MultiMap&) const; |
---|
103 | |
---|
104 | }; |
---|
105 | |
---|
106 | }}} // of namespace statistics, yat, and theplu |
---|
107 | |
---|
108 | #endif |
---|