source: trunk/test/normalization_test.cc @ 1463

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

fixing compilation errors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: normalization_test.cc 1463 2008-09-01 21:34:15Z peter $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Suite.h"
25
26#include "yat/normalization/Centralizer.h"
27#include "yat/normalization/ColumnNormalizer.h"
28#include "yat/normalization/QuantileNormalizer.h"
29
30#include "yat/utility/Matrix.h"
31
32#include <vector>
33
34using namespace theplu::yat;
35void test_centralizer(test::Suite&);
36void test_column_normalizer(test::Suite&);
37void test_quantile_normalize(test::Suite&);
38
39int main(int argc, char* argv[])
40{ 
41  test::Suite suite(argc, argv);
42  suite.err() << "testing normalizations ... " << std::endl;
43
44  test_centralizer(suite);
45  test_quantile_normalize(suite);
46
47  return suite.return_value();
48}
49
50
51void test_centralizer(test::Suite& suite)
52{
53  suite.err() << "Testing Centralizer\n";
54  std::vector<double> vec;
55  vec.push_back(1);
56  vec.push_back(2);
57  vec.push_back(3);
58  normalization::Centralizer<> c;
59  c(vec.begin(), vec.end(), vec.begin());
60  for (size_t i=0; i<vec.size(); ++i)
61    suite.add(suite.equal(vec[i], static_cast<double>(i)-1.0));
62}
63
64
65void test_column_normalize(test::Suite& suite)
66{
67  suite.err() << "Testing QuantileNormalizer\n";
68 
69  utility::Matrix m(2,2);
70  m(0,0) = 0;
71  m(0,1) = 10;
72  m(1,0) = 2;
73  m(1,1) = 4;
74  normalization::QuantileNormalizer qn;
75  qn(m, m);
76  suite.err() << "Testing m(0,0)\n";
77  suite.add(suite.equal(m(0,0), 2));
78  suite.err() << "Testing m(0,1)\n";
79  suite.add(suite.equal(m(0,1), 6));
80  suite.err() << "Testing m(1,0)\n";
81  suite.add(suite.equal(m(1,0), 6));
82  suite.err() << "Testing m(1,1)\n";
83  suite.add(suite.equal(m(1,1), 2));
84}
85
86void test_quantile_normalize(test::Suite& suite)
87{
88  suite.err() << "Testing QuantileNormalizer\n";
89 
90  utility::Matrix m(2,2);
91  m(0,0) = 0;
92  m(0,1) = 10;
93  m(1,0) = 2;
94  m(1,1) = 4;
95  normalization::QuantileNormalizer qn;
96  qn(m, m);
97  suite.err() << "Testing m(0,0)\n";
98  suite.add(suite.equal(m(0,0), 2));
99  suite.err() << "Testing m(0,1)\n";
100  suite.add(suite.equal(m(0,1), 6));
101  suite.err() << "Testing m(1,0)\n";
102  suite.add(suite.equal(m(1,0), 6));
103  suite.err() << "Testing m(1,1)\n";
104  suite.add(suite.equal(m(1,1), 2));
105}
106
Note: See TracBrowser for help on using the repository browser.