Changeset 2720


Ignore:
Timestamp:
Apr 12, 2012, 5:40:00 AM (11 years ago)
Author:
Peter
Message:

ROC: remove a data value. closes #688

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/roc.cc

    r2718 r2720  
    5454void test_p_with_weights(test::Suite& suite);
    5555void test_p_with_weights_and_ties(test::Suite& suite);
     56void test_remove(test::Suite& suite);
    5657void test_ties(test::Suite& suite);
    5758
     
    120121  test_empty(suite);
    121122  test_p_with_weights(suite);
     123  test_remove(suite);
    122124  return suite.return_value();
    123125}
     
    426428  }
    427429}
     430
     431void test_remove(test::Suite& suite)
     432{
     433  using statistics::ROC;
     434  ROC roc;
     435  roc.add(1, true);
     436  roc.add(2, false);
     437  ROC roc2(roc);
     438  if (!suite.add(suite.equal(roc.area(), roc2.area())))
     439    suite.out() << "test_remove failed: copy failed\n";
     440  roc.add(2.3, true, 1.2);
     441  try {
     442    roc.remove(2.3, true, 1.2);
     443  }
     444  catch (std::runtime_error& e) {
     445    suite.add(false);
     446    suite.out() << "exception what(): " << e.what() << "\n";
     447  }
     448  if (!suite.add(suite.equal(roc.area(), roc2.area())))
     449    suite.out() << "test remove failed\n";
     450  try {
     451    roc.remove(2, true);
     452    suite.out() << "no exception thrown\n";
     453    suite.add(false);
     454  }
     455  catch (std::runtime_error& e) {
     456    suite.add(true);
     457  }
     458}
  • trunk/yat/statistics/ROC.cc

    r2718 r2720  
    2525#include "AUC.h"
    2626
     27#include "yat/utility/Exception.h"
     28
    2729#include <gsl/gsl_cdf.h>
    2830
     
    3133#include <cmath>
    3234#include <limits>
     35#include <sstream>
    3336#include <utility>
    3437
     
    226229
    227230
     231  void ROC::remove(double value, bool target, double weight)
     232  {
     233    std::pair<Map::iterator, Map::iterator> iter = multimap_.equal_range(value);
     234    while (iter.first!=iter.second) {
     235      if (iter.first->second.first==target && iter.first->second.first==target){
     236        multimap_.erase(iter.first);
     237        return;
     238      }
     239      ++iter.first;
     240    }
     241    std::stringstream ss;
     242    ss << "ROC::remove(" << value << "," << target << "," << weight << "): "
     243       << "no such element";
     244    throw utility::runtime_error(ss.str());
     245  }
     246
     247
    228248  void ROC::reset(void)
    229249  {
  • trunk/yat/statistics/ROC.h

    r2719 r2720  
    190190    */
    191191    double p_value(void) const;
     192
     193    /**
     194       \brief remove a data value
     195
     196       A data point with identical \a value, \a target, and \a weight
     197       must have beed added prior calling this function; else an
     198       exception is thrown.
     199
     200       \since New in yat 0.9
     201     */
     202    void remove(double value, bool target, double weight=1.0);
    192203
    193204    /**
Note: See TracChangeset for help on using the changeset viewer.