Changeset 2736


Ignore:
Timestamp:
May 29, 2012, 12:06:01 PM (9 years ago)
Author:
Peter
Message:

fixes #702

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/roc.cc

    r2720 r2736  
    350350  }
    351351  double p_value = roc.p_value_one_sided();
    352   roc.p_value_one_sided();
    353352  if (!suite.add(suite.equal(p_value, static_cast<double>(k)/perm))) {
    354353    suite.out() << "area: " << roc.area() << "\n"
     
    404403  statistics::Averager averager;
    405404  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());
    407406    statistics::ROC roc2;
    408407    for (size_t j=0; j<x.size(); ++j)
  • trunk/yat/statistics/ROC.h

    r2732 r2736  
    3131#include <gsl/gsl_randist.h>
    3232
     33#include <algorithm>
    3334#include <map>
    3435#include <utility>
     36#include <vector>
    3537
    3638namespace theplu {
     
    209211  private:
    210212    typedef std::multimap<double, std::pair<bool, double> > Map;
     213    typedef std::vector<std::pair<bool, Map::mapped_type> > Vector;
    211214
    212215    // struct used in count functions
     
    260263     */
    261264    template <typename Iterator>
    262     double count(Map& weights, Iterator iter, Iterator last,
     265    double count(Vector& weights, Iterator iter, Iterator last,
    263266                 double threshold, double sum, const Weights& weight) const;
    264267
     
    269272     */
    270273    template <typename Iterator>
    271     double count(Map& weights, Iterator iter, Iterator last,
     274    double count(Vector& weights, Iterator iter, Iterator last,
    272275                 double threshold, double sum, Weights weight,
    273276                 const std::pair<bool, double>& entry) const;
     
    352355  double ROC::count(Iterator first, Iterator last, double threshold) const
    353356  {
    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
    355363    ROC::Weights w;
    356364    w.small_pos = pos_weights_.sum_x();
    357365    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);
    359367  }
    360368
     
    362370
    363371  template <typename Iterator>
    364   double ROC::count(Map& weights, Iterator iter, Iterator last,
     372  double ROC::count(ROC::Vector& v, Iterator iter, Iterator last,
    365373                    double threshold, double sum, const Weights& w) const
    366374  {
    367375    double result = 0.0;
    368376    // 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;
    379388  }
    380389
     390
    381391  template <typename Iterator>
    382   double ROC::count(Map& weights, Iterator iter, Iterator last,
     392  double ROC::count(Vector& weights, Iterator iter, Iterator last,
    383393                    double threshold, double sum, Weights w,
    384394                    const std::pair<bool, double>& entry) const
     
    387397
    388398    Iterator next(iter);
     399    YAT_ASSERT(next!=last);
    389400    ++next;
    390401
Note: See TracChangeset for help on using the changeset viewer.