Changeset 1420 for trunk


Ignore:
Timestamp:
Aug 20, 2008, 7:33:39 PM (13 years ago)
Author:
Peter
Message:

fixing the weighted implementation of Percentiler - refs #366. Some documentation is needed before closing the ticket.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r1418 r1420  
    4949TESTS = $(check_PROGRAMS)
    5050
    51 XFAIL_TESTS = statistics_test
     51# tests not passing through yet
     52XFAIL_TESTS =
    5253
    5354if HAVE_DOXYGEN
    5455TESTS += documentation_test.sh
    5556endif
    56 
    57 
    58 # tests that fail are only built not included in check
    59 #check_PROGRAMS +=
    6057
    6158LDADD = @top_builddir@/$(YAT_LIB_LOCATION)/libyat.la libyattest.la
  • trunk/test/statistics_test.cc

    r1418 r1420  
    9797  x.reserve(6);
    9898  for (unsigned int i=0; i<5; i++){
    99     x.push_back(static_cast<double>(i));
     99    x.push_back(static_cast<double>(i+1));
    100100  }
    101   test_percentiler(suite, x.begin(), x.end(), 50, 2);
    102   x.push_back(5);
    103   test_percentiler(suite, x.begin(), x.end(), 50, 2.5);
    104   test_percentiler(suite, x.begin(), x.end(), 25, 1);
    105   test_percentiler(suite, x.begin(), x.end(), 0, 0);
    106   test_percentiler(suite, x.begin(), x.end(), 10, 0);
     101  test_percentiler(suite, x.begin(), x.end(), 50, 3);
     102  x.push_back(6);
     103  test_percentiler(suite, x.begin(), x.end(), 50, 3.5);
     104  test_percentiler(suite, x.begin(), x.end(), 25, 2);
     105  test_percentiler(suite, x.begin(), x.end(), 0, 1);
     106  test_percentiler(suite, x.begin(), x.end(), 10, 1);
    107107
    108108  suite.err() << "testing duplication of data\n";
     
    122122  }
    123123  const std::vector<utility::DataWeight> xw_orig(xw);
     124  suite.err() << "testing weighted" << std::endl;
     125  test_percentiler(suite, xw.begin(), xw.end(), 0, 1);
     126  test_percentiler(suite, xw.begin(), xw.end(), 100, 6);
     127  test_percentiler(suite, xw.begin(), xw.end(), 49, 3);
     128  test_percentiler(suite, xw.begin(), xw.end(), 51, 4);
     129  test_percentiler(suite, xw.begin(), xw.end(), 50, 3.5);
     130  test_percentiler(suite, x.begin(), x.end(), 10, 1);
     131
    124132  suite.err() << "testing weighted with unity weights" << std::endl;
    125133  cmp_percentiler(suite, x.begin(), x.end(), xw.begin(), xw.end());
     
    149157  double x = percentile2(first, last, p);
    150158  if (!suite.add(suite.equal(x, correct, 10))) {
    151     suite.err() << "Error in percentile2\n";
     159    suite.err() << "Error in percentile2 for " << p << "th percentile \n";
    152160    suite.err() << "  calculated value: " << x << "\n";
    153161    suite.err() << "  expected value: " << correct << "\n";
  • trunk/yat/statistics/Percentiler.h

    r1418 r1420  
    146146      double w_bound=perc_/100.0*accum_w.back();
    147147      std::vector<double>::const_iterator upper(accum_w.begin());
    148       double allowed_error=1e-10;
    149       while (upper != accum_w.end() && *upper < w_bound + allowed_error)
     148      double margin=1e-10;
     149      while (*upper <= w_bound+margin && upper!=accum_w.end())
    150150        ++upper;
     151      if (upper==accum_w.end())
     152        --upper;
    151153      std::vector<double>::const_iterator lower(upper);
    152       while (lower!=accum_w.begin() && *lower > w_bound - allowed_error)
     154      while ( *(lower-1)>=w_bound-margin && lower>accum_w.begin())
    153155        --lower;
     156     
    154157      return (trait.data(first+(upper-accum_w.begin()))+
    155               trait.data(first+(lower-accum_w.begin()+1)))/2;
     158              trait.data(first+(lower-accum_w.begin())))/2;
    156159    }
    157160
Note: See TracChangeset for help on using the changeset viewer.