source: trunk/test/statistics_test.cc @ 588

Last change on this file since 588 was 588, checked in by Markus Ringnér, 15 years ago

Added statistics functions to calculate the higher moments: skewness and kurtosis using gsl functions

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 738 bytes
Line 
1// $Id: statistics_test.cc 588 2006-06-21 15:43:29Z markus $
2
3#include <c++_tools/statistics/utility.h>
4#include <c++_tools/gslapi/vector.h>
5
6#include <vector>
7#include <cstdlib>
8#include <iostream>
9#include <cmath>
10
11int main()
12{ 
13  using namespace theplu;
14  gslapi::vector gsl_vec(10);
15  std::vector<double> data;
16  for (unsigned int i=0; i<10; i++){
17    data.push_back(static_cast<double>(i));
18    gsl_vec(i)=i;
19  }
20
21  double m=statistics::median(data);
22  double m_gsl=statistics::median(gsl_vec);
23  if (m!=4.5 || m!=m_gsl)
24    return -1;
25
26  double tolerance=1e-10;
27  double skewness_gsl=statistics::skewness(gsl_vec);
28  if (fabs(skewness_gsl)>tolerance)
29    return -1;
30  double kurtosis_gsl=statistics::kurtosis(gsl_vec);
31  if (fabs(kurtosis_gsl+1.5616363636363637113)>tolerance) 
32    return -1; 
33  return 0;
34}
Note: See TracBrowser for help on using the repository browser.