Changeset 1617 for trunk


Ignore:
Timestamp:
Nov 6, 2008, 2:28:02 PM (13 years ago)
Author:
Peter
Message:

refs #457 - adding a test with two samples and avoid shadowing variables

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/kolmogorov_smirnov_test.cc

    r1613 r1617  
    2424#include "yat/statistics/Averager.h"
    2525#include "yat/statistics/KolmogorovSmirnov.h"
     26#include "yat/random/random.h"
    2627
    2728#include <cmath>
     
    3132
    3233void test_one_sample(test::Suite&);
     34void test_two_sample(test::Suite&);
    3335void test_p_value(test::Suite&);
    3436void test_reset(test::Suite&);
     
    3941
    4042  test_one_sample(suite);
     43  test_two_sample(suite);
    4144  //test_p_value(suite);
    4245  test_reset(suite);
     
    8487}
    8588
     89
     90void test_two_sample(test::Suite& suite)
     91{
     92  suite.err() << "testing two sample\n";
     93  statistics::KolmogorovSmirnov ks;
     94  for (size_t i=0; i<5; ++i)
     95    ks.add(i+0.5, i<2);
     96  suite.add(suite.equal(ks.score(), 1.0));
     97  size_t n=1000;
     98  double p = ks.p_value(n);
     99  double p_correct = 0.2;
     100  double margin=10*std::sqrt(n*p_correct)/n;
     101  if (std::abs(p-p_correct)>margin) {
     102    suite.add(false);
     103    suite.err() << "Error: p = " << p << "\n"
     104                << "correct p would be: " << p_correct << "\n"
     105                << "expected a difference less than " << margin << "margin\n";
     106    suite.err() << p << std::endl;
     107  }
     108}
     109
     110
    86111void test_p_value(test::Suite& suite)
    87112{
  • trunk/yat/statistics/KolmogorovSmirnov.cc

    r1612 r1617  
    8989      std::deque<bool>::const_iterator target_i(targets.begin());
    9090      const_iter end(data_.end());
    91       for (const_iter i(data_.begin()); i!=end; ++i, ++target_i)
    92         ks.add(i->first.first, *target_i, i->first.second);
     91      for (const_iter iter(data_.begin()); iter!=end; ++iter, ++target_i)
     92        ks.add(iter->first.first, *target_i, iter->first.second);
    9393     
    9494      if (ks.score()>=score())
Note: See TracChangeset for help on using the changeset viewer.