source: trunk/src/ROC.cc @ 72

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

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1// $Id: ROC.cc 72 2004-05-03 09:39:09Z peter $
2
3// System includes
4#include <algorithm>
5#include <utility>
6#include <vector>
7
8// Thep C++ Tools
9#include "ROC.h"
10#include "stl_utility.h"
11#include "vector.h"
12
13namespace theplu {
14namespace cpptools { 
15
16  ROC::ROC(const gslapi::vector& target, const gslapi::vector& value) 
17 
18    : value_(), nof_pos_(0), minimum_size_(10)
19
20       
21  {
22    for (unsigned int i=0; i<target.size(); i++){
23      int targ=static_cast<int>(target(i));
24      std::pair<int, double> tmp(targ, value(i));
25      value_.push_back(tmp);
26      if (targ==1)
27        nof_pos_++;
28    }
29    sort(value_.begin(),value_.end(),
30         pair_value_compare<int,double>());
31   
32  }
33
34
35  double ROC::area()
36  {
37    using namespace std;
38    double area=0;
39    for (unsigned int i=0; i<value_.size(); i++)
40      if (value_[i].first==1)
41        area+=i;
42    // Normalizing the area to 0-1
43    area = (2*area/nof_pos_ - nof_pos_ + 1)/(2*value_.size() - 2*nof_pos_);
44    return area;
45  }
46
47
48  double ROC::get_p(const double area)
49  {
50    double p;
51    if (nof_pos_ < minimum_size_ & value_.size()-nof_pos_ < minimum_size_)
52      p = get_p_exact(area*nof_pos_*(value_.size()-nof_pos_), 
53                           nof_pos_, value_.size()-nof_pos_);
54    else
55    p = get_p_approx(area);
56    return p;
57  }
58
59
60  double ROC::get_p_approx(const double area) 
61  {
62    double x = area-0.5;
63    double sigma = ((value_.size()-nof_pos_)*nof_pos_*value_.size()/12/
64                    (2*value_.size() - 2*nof_pos_));
65    double p = gsl_cdf_gaussian_Q(x, sigma);
66    return p;
67  }
68
69
70  double ROC::get_p_exact(const double block, const double nof_pos, 
71                            const double nof_neg)
72  {
73    double p;
74    if (block <= 0.0)
75      p = 1.0;
76    else if (block > nof_neg*nof_pos)
77      p = 0.0;
78    else {
79      double p1 = get_p_exact(block-nof_neg, nof_pos-1, nof_neg);
80      double p2 = get_p_exact(block, nof_pos, nof_neg-1);
81      p = nof_pos/(nof_pos+nof_neg)*p1 + nof_neg/(nof_pos+nof_neg)*p2;
82    }
83    return p;
84  }
85
86}} // of namespace cpptools and namespace theplu
Note: See TracBrowser for help on using the repository browser.