Changeset 1617
- Timestamp:
- Nov 6, 2008, 2:28:02 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/kolmogorov_smirnov_test.cc
r1613 r1617 24 24 #include "yat/statistics/Averager.h" 25 25 #include "yat/statistics/KolmogorovSmirnov.h" 26 #include "yat/random/random.h" 26 27 27 28 #include <cmath> … … 31 32 32 33 void test_one_sample(test::Suite&); 34 void test_two_sample(test::Suite&); 33 35 void test_p_value(test::Suite&); 34 36 void test_reset(test::Suite&); … … 39 41 40 42 test_one_sample(suite); 43 test_two_sample(suite); 41 44 //test_p_value(suite); 42 45 test_reset(suite); … … 84 87 } 85 88 89 90 void 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 86 111 void test_p_value(test::Suite& suite) 87 112 { -
trunk/yat/statistics/KolmogorovSmirnov.cc
r1612 r1617 89 89 std::deque<bool>::const_iterator target_i(targets.begin()); 90 90 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); 93 93 94 94 if (ks.score()>=score())
Note: See TracChangeset
for help on using the changeset viewer.