# source:trunk/src/ROC.h@148

Last change on this file since 148 was 148, checked in by Peter, 19 years ago

modified score function

• Property svn:eol-style set to native
• Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line
1// $Id: ROC.h 148 2004-09-09 13:22:41Z peter$
2
3#ifndef _theplu_cpptools_roc_
4#define _theplu_cpptools_roc_
5
6// C++ tools include
7/////////////////////
8#include "Score.h"
9#include "vector.h"
10
11// Standard C++ includes
12////////////////////////
13#include <utility>
14#include <vector>
15
16namespace theplu {
17namespace cpptools {
18  ///
19  /// Class for ROC (Reciever Operating Characteristic).
20  ///
21
22  class ROC : public Score
23  {
24
25  public:
26    ///
27    /// Default constructor
28    ///
29    ROC();
30
31    ///
32    /// Destructor
33    ///
34    virtual ~ROC(void) {};
35
36    /// Function taking \a value, \a target (+1 or -1) and vector
37    /// defining what samples to use. The score is equivalent to
38    /// Mann-Whitney statistics @return the area under the ROC
39    /// curve. If the area is less than 0.5, is 1-area returned.
40    ///
41    double score(const gslapi::vector& value, const gslapi::vector& target,
42                 const std::vector<size_t>& = std::vector<size_t>());
43
44    /// Function taking values, target, weight and a vector defining
45    /// what samples to use. The area is defines as \f$\frac{\sum 46 /// w^+w^-}{\sum w^+w^-}\f$, where the sum in the numerator goes
47    /// over all pairs where value+ is larger than value-. The
48    /// denominator goes over all pairs. @return wheighted version of
49    /// area under the ROC curve. If the area is less than 0.5, is
50    /// 1-area returned.
51    ///
52    double score(const gslapi::vector&, const gslapi::vector&,
53                 const gslapi::vector&,
54                 const std::vector<size_t>& = std::vector<size_t>());
55
56    ///
57    ///Calculates the p-value, i.e. the probability of observing an area
58    ///equally or larger if the null hypothesis is true. If P is near zero,
59    ///this casts doubt on this hypothesis. The null hypothesis is that the
60    ///values from the 2 classes are generated from 2 identical
61    ///distributions. The alternative is that the median of the first
62    ///distribution is shifted from the median of the second distribution by a
63    ///non-zero amount. If the smallest group size is larger than minimum_size
64    ///(default = 10), then P is calculated using a normal approximation.
65    /// @return the one-sided p-value
66    ///
67    double p_value() ;
68
69    ///
70    /// @return the targets in train_set sorted with respect to the
71    /// corresponding data
72    ///
73    gslapi::vector ROC::target(void) const;
74
75    ///
76    /// Changes minimum_size , i.e. the threshold when a normal
77    /// approximation is used for the p-value calculation.
78    ///
79    inline void minimum_size(const u_int minimum_size)
80    {minimum_size_ = minimum_size; }
81
82  private:
83    double area_;
84    gslapi::vector data_;
85    u_int minimum_size_;
86    u_int nof_pos_;
87    gslapi::vector target_;
88    std::vector<size_t> train_set_;
89    std::vector<std::pair<double, double> > value_;
90    /// pair of target and data. should always be sorted with respect to
91    /// data.
92    gslapi::vector weight_;
93
94    ///
95    ///
96    /// Implemented as in MatLab 13.1
97    /// @return the p-value
98    ///
99    double ROC::get_p_approx(const double) const;
100
101    ///
102    /// @return the p-value
103    ///
104    double ROC::get_p_exact(const double, const double,
105                            const double);
106
107    ///
108    /// sorting value_, should always be done when changing train_set_
109    ///
110    void ROC::sort();
111
112  };
113
114  ///
115  /// The output operator for the ROC class. The output is an Nx2
116  /// matrix, where the first column is the sensitivity and second
117  /// is the specificity.
118  ///
119  std::ostream& operator<< (std::ostream& s, const ROC&);
120
121
122}} // of namespace cpptools and namespace theplu
123
124#endif
125
Note: See TracBrowser for help on using the repository browser.