1 | // $Id: statistics_test.cc 865 2007-09-10 19:41:04Z peter $ |
---|

2 | |
---|

3 | /* |
---|

4 | Copyright (C) 2004 Jari Häkkinen, Peter Johansson |
---|

5 | Copyright (C) 2005 Peter Johansson |
---|

6 | Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson |
---|

7 | |
---|

8 | This file is part of the yat library, http://trac.thep.lu.se/trac/yat |
---|

9 | |
---|

10 | The yat library is free software; you can redistribute it and/or |
---|

11 | modify it under the terms of the GNU General Public License as |
---|

12 | published by the Free Software Foundation; either version 2 of the |
---|

13 | License, or (at your option) any later version. |
---|

14 | |
---|

15 | The yat library is distributed in the hope that it will be useful, |
---|

16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|

17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|

18 | General Public License for more details. |
---|

19 | |
---|

20 | You should have received a copy of the GNU General Public License |
---|

21 | along with this program; if not, write to the Free Software |
---|

22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|

23 | 02111-1307, USA. |
---|

24 | */ |
---|

25 | |
---|

26 | #include "yat/statistics/utility.h" |
---|

27 | #include "yat/utility/vector.h" |
---|

28 | |
---|

29 | #include <vector> |
---|

30 | #include <cstdlib> |
---|

31 | #include <iostream> |
---|

32 | #include <cmath> |
---|

33 | |
---|

34 | int main() |
---|

35 | { |
---|

36 | using namespace theplu::yat; |
---|

37 | utility::vector gsl_vec(10); |
---|

38 | std::vector<double> data; |
---|

39 | for (unsigned int i=0; i<10; i++){ |
---|

40 | data.push_back(static_cast<double>(i)); |
---|

41 | gsl_vec(i)=i; |
---|

42 | } |
---|

43 | |
---|

44 | double m=statistics::median(data); |
---|

45 | double m_gsl=statistics::median(gsl_vec); |
---|

46 | if (m!=4.5 || m!=m_gsl) |
---|

47 | return -1; |
---|

48 | |
---|

49 | double tolerance=1e-10; |
---|

50 | double skewness_gsl=statistics::skewness(gsl_vec); |
---|

51 | if (fabs(skewness_gsl)>tolerance) |
---|

52 | return -1; |
---|

53 | double kurtosis_gsl=statistics::kurtosis(gsl_vec); |
---|

54 | if (fabs(kurtosis_gsl+1.5616363636363637113)>tolerance) |
---|

55 | return -1; |
---|

56 | return 0; |
---|

57 | } |
---|