Changeset 103 for trunk/src/ROC.cc
 Timestamp:
 Jun 15, 2004, 4:29:15 PM (19 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/ROC.cc
r102 r103 2 2 3 3 // System includes 4 #include <iostream> 4 5 //#include <algorithm> 5 6 //#include <utility> … … 19 20 20 21 { 21 for (unsigned int i=0; i<target.size(); i++){ 22 int targ=static_cast<int>(target(i)); 23 std::pair<int, double> tmp(targ, value(i)); 24 value_.push_back(tmp); 25 if (targ==1) 26 nof_pos_++; 27 } 28 sort(value_.begin(),value_.end(), 29 pair_value_compare<int,double>()); 30 22 sort(target, value); 31 23 } 32 24 … … 36 28 { 37 29 } 38 39 40 double ROC::score(const gslapi::vector& target, const gslapi::vector& value)41 {42 for (unsigned int i=0; i<target.size(); i++){43 int targ=static_cast<int>(target(i));44 std::pair<int, double> tmp(targ, value(i));45 value_.push_back(tmp);46 if (targ==1)47 nof_pos_++;48 }49 sort(value_.begin(),value_.end(),50 pair_value_compare<int,double>());51 double area_=0;52 for (unsigned int i=0; i<value_.size(); i++)53 if (value_[i].first==1)54 area_+=i;55 // Normalizing the area to 0156 area_ = (area_/nof_pos_  (nof_pos_  1)/2 )/(value_.size()  nof_pos_);57 58 return area_;59 }60 61 double ROC::score()62 {63 if (area_==1){64 double area_=0;65 for (unsigned int i=0; i<value_.size(); i++)66 if (value_[i].first==1)67 area_+=i;68 // Normalizing the area to 0169 area_ = (area_/nof_pos_  (nof_pos_  1)/2 )/(value_.size()  nof_pos_);70 }71 return area_;72 }73 74 75 double ROC::p_value(void)76 {77 if (area_==1)78 area_ = score();79 double p;80 if (nof_pos_ < minimum_size_ & value_.size()nof_pos_ < minimum_size_)81 p = get_p_exact(area_*nof_pos_*(value_.size()nof_pos_),82 nof_pos_, value_.size()nof_pos_);83 else84 p = get_p_approx(area_);85 return p;86 }87 88 30 89 31 double ROC::get_p_approx(const double area) const … … 104 46 } 105 47 106 107 48 double ROC::get_p_exact(const double block, const double nof_pos, 108 49 const double nof_neg) … … 121 62 } 122 63 64 double ROC::p_value(void) 65 { 66 if (area_==1) 67 area_ = score(); 68 double p; 69 if (nof_pos_ < minimum_size_ & value_.size()nof_pos_ < minimum_size_) 70 p = get_p_exact(area_*nof_pos_*(value_.size()nof_pos_), 71 nof_pos_, value_.size()nof_pos_); 72 else 73 p = get_p_approx(area_); 74 return p; 75 } 76 77 double ROC::score() 78 { 79 if (area_==1){ 80 double area_=0; 81 for (unsigned int i=0; i<value_.size(); i++) 82 if (value_[i].first==1) 83 area_+=i; 84 // Normalizing the area to 01 85 area_ = (area_/nof_pos_  (nof_pos_  1)/2 )/(value_.size()  nof_pos_); 86 } 87 return area_; 88 } 89 90 double ROC::score(const gslapi::vector& target, const gslapi::vector& value) 91 { 92 sort(target, value); 93 double area_=0; 94 for (unsigned int i=0; i<value_.size(); i++) 95 if (value_[i].first==1) 96 area_+=i; 97 // Normalizing the area to 01 98 area_ = (area_/nof_pos_  (nof_pos_  1)/2 )/(value_.size()  nof_pos_); 99 100 return area_; 101 } 102 103 void ROC::sort(const gslapi::vector& target, const gslapi::vector& value) 104 { 105 for (unsigned int i=0; i<target.size(); i++){ 106 int targ=static_cast<int>(target(i)); 107 std::pair<int, double> tmp(targ, value(i)); 108 value_.push_back(tmp); 109 if (targ==1) 110 nof_pos_++; 111 } 112 std::sort(value_.begin(),value_.end(), 113 pair_value_compare<int,double>()); 114 } 115 116 gslapi::vector ROC::target(void) const 117 { 118 gslapi::vector target(value_.size()); 119 for(size_t i=0; i<target.size(); ++i) 120 target(i) = value_[i].first; 121 return target; 122 } 123 124 std::ostream& operator<<(std::ostream& s, const ROC& r) 125 { 126 s.setf( std::ios::dec ); 127 s.precision(12); 128 double sens = 1; 129 double spec = 0; 130 gslapi::vector target = r.target(); 131 size_t n = target.size(); 132 double nof_pos = (target.sum()+n)/2; 133 for(size_t i=0; i<n1; ++i) { 134 s << sens << "\t"; 135 s << spec << std::endl; 136 if (target(i)==1) 137 spec = 1/(nnof_pos); 138 else 139 sens = 1/nof_pos; 140 } 141 s << sens << "\t"; 142 s << spec << std::endl; 143 return s; 144 } 145 146 123 147 }} // of namespace cpptools and namespace theplu
Note: See TracChangeset
for help on using the changeset viewer.