Ignore:
Timestamp:
Jan 7, 2009, 11:53:05 PM (12 years ago)
Author:
Peter
Message:

class KolmogorovSmirnov?:
add (sorted) range (fixes #462)
allow copy and assignment
add a shuffle function
p_value calculation now scales linearly with number of data points and
not N*logN as before

configure.ac: added a test to see if std::multiset::iterator is mutable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/kolmogorov_smirnov_test.cc

    r1688 r1701  
    22
    33/*
    4   Copyright (C) 2008 Peter Johansson
     4  Copyright (C) 2008, 2009 Peter Johansson
    55
    66  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2222#include "Suite.h"
    2323
     24#include "yat/random/random.h"
    2425#include "yat/statistics/Averager.h"
    2526#include "yat/statistics/KolmogorovSmirnov.h"
    26 #include "yat/random/random.h"
    2727
    2828#include <cmath>
     29#include <deque>
    2930#include <iostream>
     31#include <vector>
    3032
    3133using namespace theplu::yat;
     
    3436void test_two_sample(test::Suite&);
    3537void test_p_value(test::Suite&);
     38void test_shuffle(test::Suite&);
     39void test_range(test::Suite&);
    3640void test_reset(test::Suite&);
    3741void test_ties(test::Suite&);
     
    4448  test_two_sample(suite);
    4549  test_p_value(suite);
     50  test_shuffle(suite);
     51  test_range(suite);
    4652  test_reset(suite);
    4753  test_ties(suite);
     
    136142}
    137143
     144
     145void test_range(test::Suite& suite)
     146{
     147  suite.err() << "testing range" << std::endl;
     148  std::deque<bool> labels;
     149  for (size_t i=0; i<10; ++i) {
     150    labels.push_back(i<5);
     151  }
     152  std::vector<statistics::KolmogorovSmirnov::Element> data;
     153  statistics::KolmogorovSmirnov::Element elem;
     154  elem.weight = 1.0;
     155  for (size_t i=0; i<10; ++i) {
     156    elem.value = i;
     157    elem.label = labels[i];
     158    data.push_back(elem);
     159  }
     160  statistics::KolmogorovSmirnov ks;
     161  ks.add(data.begin(), data.end());
     162  suite.add(suite.equal(ks.score(), 1.0));
     163 
     164  // testing that adding a range gives same result as adding elements
     165  // sequentially
     166  statistics::KolmogorovSmirnov ks2;
     167  for (size_t i=0; i<data.size(); ++i)
     168    ks2.add(data[i].value, data[i].label, data[i].weight);
     169  suite.add(suite.equal(ks2.signed_score(), ks.signed_score()));
     170
     171  theplu::yat::random::random_shuffle(labels.begin(), labels.end());
     172  for (size_t i=0; i<data.size(); ++i) {
     173    data[i].label = labels[i];
     174  }
     175  ks.reset();
     176  ks.add(data.begin(), data.end());
     177  ks2.reset();
     178  for (size_t i=0; i<data.size(); ++i)
     179    ks2.add(data[i].value, data[i].label, data[i].weight);
     180  suite.add(suite.equal(ks2.signed_score(), ks.signed_score()));
     181}
     182
     183
    138184void test_reset(test::Suite& suite)
    139185{
     
    163209  suite.add(suite.equal(ks.score(), 1.0-0.2));
    164210}
     211
     212
     213void test_shuffle(test::Suite& suite)
     214{
     215  suite.err() << "testing shuffle" << std::endl;
     216  statistics::KolmogorovSmirnov ks;
     217  for (size_t i=0; i<10; ++i)
     218    ks.add(i, i<5);
     219  ks.shuffle();
     220}
     221
     222
Note: See TracChangeset for help on using the changeset viewer.