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