Changeset 2736
- Timestamp:
- May 29, 2012, 12:06:01 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/roc.cc
r2720 r2736 350 350 } 351 351 double p_value = roc.p_value_one_sided(); 352 roc.p_value_one_sided();353 352 if (!suite.add(suite.equal(p_value, static_cast<double>(k)/perm))) { 354 353 suite.out() << "area: " << roc.area() << "\n" … … 404 403 statistics::Averager averager; 405 404 for (size_t i=1; i<=perm; ++i) { 406 random::random_shuffle(x.begin(), x.end());405 theplu::yat::random::random_shuffle(x.begin(), x.end()); 407 406 statistics::ROC roc2; 408 407 for (size_t j=0; j<x.size(); ++j) -
trunk/yat/statistics/ROC.h
r2732 r2736 31 31 #include <gsl/gsl_randist.h> 32 32 33 #include <algorithm> 33 34 #include <map> 34 35 #include <utility> 36 #include <vector> 35 37 36 38 namespace theplu { … … 209 211 private: 210 212 typedef std::multimap<double, std::pair<bool, double> > Map; 213 typedef std::vector<std::pair<bool, Map::mapped_type> > Vector; 211 214 212 215 // struct used in count functions … … 260 263 */ 261 264 template <typename Iterator> 262 double count( Map& weights, Iterator iter, Iterator last,265 double count(Vector& weights, Iterator iter, Iterator last, 263 266 double threshold, double sum, const Weights& weight) const; 264 267 … … 269 272 */ 270 273 template <typename Iterator> 271 double count( Map& weights, Iterator iter, Iterator last,274 double count(Vector& weights, Iterator iter, Iterator last, 272 275 double threshold, double sum, Weights weight, 273 276 const std::pair<bool, double>& entry) const; … … 352 355 double ROC::count(Iterator first, Iterator last, double threshold) const 353 356 { 354 Map map(multimap_); 357 Vector vec; 358 vec.reserve(multimap_.size()); 359 // copy values from multimap_ to v 360 for (Map::const_iterator i = multimap_.begin(); i!=multimap_.end(); ++i) 361 vec.push_back(std::make_pair(false, i->second)); 362 355 363 ROC::Weights w; 356 364 w.small_pos = pos_weights_.sum_x(); 357 365 w.small_neg = neg_weights_.sum_x(); 358 return count( map, first, last, threshold*w.small_pos*w.small_neg, 0, w);366 return count(vec, first, last, threshold*w.small_pos*w.small_neg, 0, w); 359 367 } 360 368 … … 362 370 363 371 template <typename Iterator> 364 double ROC::count( Map& weights, Iterator iter, Iterator last,372 double ROC::count(ROC::Vector& v, Iterator iter, Iterator last, 365 373 double threshold, double sum, const Weights& w) const 366 374 { 367 375 double result = 0.0; 368 376 // loop over all elements 369 for (Map::iterator i=weights.begin(); i!=weights.end(); ++i) { 370 Map::value_type save = *i; 371 Map::iterator hint = i; 372 ++hint; 373 weights.erase(i); 374 result += count(weights, iter, last, threshold, sum, w, save.second); 375 i = weights.insert(hint, save); 376 } 377 YAT_ASSERT(weights.size()); 378 return result/weights.size(); 377 int nof_elements = 0; 378 for (ROC::Vector::iterator i=v.begin(); i!=v.end(); ++i) { 379 if (i->first) 380 continue; 381 i->first = true; 382 result += count(v, iter, last, threshold, sum, w, i->second); 383 i->first = false; 384 ++nof_elements; 385 } 386 YAT_ASSERT(nof_elements); 387 return result/nof_elements; 379 388 } 380 389 390 381 391 template <typename Iterator> 382 double ROC::count( Map& weights, Iterator iter, Iterator last,392 double ROC::count(Vector& weights, Iterator iter, Iterator last, 383 393 double threshold, double sum, Weights w, 384 394 const std::pair<bool, double>& entry) const … … 387 397 388 398 Iterator next(iter); 399 YAT_ASSERT(next!=last); 389 400 ++next; 390 401
Note: See TracChangeset
for help on using the changeset viewer.