source: trunk/test/statistics_test.cc @ 1305

Last change on this file since 1305 was 1305, checked in by Peter, 13 years ago

Adding a functor that calculate average of a range. Also added a metafunction that return Averager or AveragerWeighted? depending on context.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1// $Id: statistics_test.cc 1305 2008-05-14 22:25:54Z 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, Peter Johansson, Markus Ringnér
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 Peter Johansson
9
10  This file is part of the yat library, http://trac.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 2 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25  02111-1307, USA.
26*/
27
28#include "Suite.h"
29
30#include "yat/statistics/utility.h"
31#include "yat/utility/Vector.h"
32
33#include <vector>
34#include <cstdlib>
35#include <iostream>
36#include <cmath>
37
38int main(int argc, char* argv[])
39{ 
40  using namespace theplu::yat;
41  test::Suite suite(argc, argv);
42
43  utility::Vector gsl_vec(10);
44  std::vector<double> data;
45  for (unsigned int i=0; i<10; i++){
46    data.push_back(static_cast<double>(i));
47    gsl_vec(i)=i;
48  }
49
50  double m=statistics::median(data.begin(), data.end());
51  double m_gsl=statistics::median(gsl_vec.begin(), gsl_vec.end());
52  if (m!=4.5 || m!=m_gsl)
53    suite.add(false);
54  statistics::percentile(data.begin(), data.end(), 100);
55  data.resize(1);
56  statistics::median(data.begin(), data.end());
57
58  double skewness_gsl=statistics::skewness(gsl_vec);
59  if (!suite.equal(1-skewness_gsl, 1.0) )
60    suite.add(false);
61  double kurtosis_gsl=statistics::kurtosis(gsl_vec);
62  if (!(std::abs(kurtosis_gsl+1.5616363636363637113)<1e-10) ) 
63    suite.add(false); 
64  statistics::Average func;
65  suite.add(suite.equal(func(gsl_vec.begin(), gsl_vec.end()),4.5));
66  // easiest way to get a weighted iterator
67  classifier::MatrixLookupWeighted mlw(10,20,2.0, 1.0);
68  suite.add(suite.equal(func(mlw.begin(), mlw.end()),2.0));
69 
70
71  return suite.return_value();
72}
Note: See TracBrowser for help on using the repository browser.