1 | #ifndef _theplu_yat_statistics_auc_ |
---|
2 | #define _theplu_yat_statistics_auc_ |
---|
3 | |
---|
4 | // $Id: AUC.h 820 2007-03-17 21:54:52Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) The authors contributing to this file. |
---|
8 | |
---|
9 | This file is part of the yat library, http://lev.thep.lu.se/trac/yat |
---|
10 | |
---|
11 | The yat library is free software; you can redistribute it and/or |
---|
12 | modify it under the terms of the GNU General Public License as |
---|
13 | published by the Free Software Foundation; either version 2 of the |
---|
14 | License, or (at your option) any later version. |
---|
15 | |
---|
16 | The yat library is distributed in the hope that it will be useful, |
---|
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
19 | General Public License for more details. |
---|
20 | |
---|
21 | You should have received a copy of the GNU General Public License |
---|
22 | along with this program; if not, write to the Free Software |
---|
23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
24 | 02111-1307, USA. |
---|
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 vector; |
---|
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 | /// |
---|
52 | /// |
---|
53 | AUC(bool absolute=true); |
---|
54 | |
---|
55 | /// Function taking \a value, \a target (+1 or -1) and vector |
---|
56 | /// defining what samples to use. The score is equivalent to |
---|
57 | /// Mann-Whitney statistics. |
---|
58 | /// @return the area under the ROC curve. If the area is less |
---|
59 | /// than 0.5 and absolute=true, 1-area is returned. Complexity is |
---|
60 | /// \f$ N\log N \f$ where \f$ N \f$ is number of samples. |
---|
61 | /// |
---|
62 | double score(const classifier::Target& target, |
---|
63 | const utility::vector& value) const; |
---|
64 | |
---|
65 | /** |
---|
66 | Function taking values, target, weight and a vector defining |
---|
67 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
68 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
69 | over all pairs where value+ is larger than value-. The |
---|
70 | denominator goes over all pairs. If target is equal to 1, |
---|
71 | sample belonges to class + otherwise sample belongs to class |
---|
72 | -. @return wheighted version of area under the ROC curve. If |
---|
73 | the area is less than 0.5 and absolute=true, 1-area is |
---|
74 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
75 | of samples. |
---|
76 | */ |
---|
77 | double score(const classifier::Target& target, |
---|
78 | const classifier::DataLookupWeighted1D& value) const; |
---|
79 | |
---|
80 | /** |
---|
81 | Function taking values, target, weight and a vector defining |
---|
82 | what samples to use. The area is defines as \f$ \frac{\sum |
---|
83 | w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes |
---|
84 | over all pairs where value+ is larger than value-. The |
---|
85 | denominator goes over all pairs. If target is equal to 1, |
---|
86 | sample belonges to class + otherwise sample belongs to class |
---|
87 | -. @return wheighted version of area under the ROC curve. If |
---|
88 | the area is less than 0.5 and absolute=true, 1-area is |
---|
89 | returned. Complexity is \f$ N^2 \f$ where \f$ N \f$ is number |
---|
90 | of samples. |
---|
91 | */ |
---|
92 | double score(const classifier::Target& target, |
---|
93 | const utility::vector& value, |
---|
94 | const utility::vector& weight) const; |
---|
95 | |
---|
96 | private: |
---|
97 | typedef std::multimap<double, std::pair<bool, double> > MultiMap; |
---|
98 | double score(const MultiMap&) const; |
---|
99 | |
---|
100 | }; |
---|
101 | |
---|
102 | }}} // of namespace statistics, yat, and theplu |
---|
103 | |
---|
104 | #endif |
---|