source: trunk/test/normalization_test.cc @ 1487

Last change on this file since 1487 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: normalization_test.cc 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2008 Peter Johansson
5
6  This file is part of the yat library, http://dev.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 3 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 yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Suite.h"
23
24#include "yat/normalization/Centralizer.h"
25#include "yat/normalization/ColumnNormalizer.h"
26#include "yat/normalization/QuantileNormalizer.h"
27
28#include "yat/utility/Matrix.h"
29
30#include <vector>
31
32using namespace theplu::yat;
33void test_centralizer(test::Suite&);
34void test_column_normalize(test::Suite&);
35void test_quantile_normalize(test::Suite&);
36
37int main(int argc, char* argv[])
38{ 
39  test::Suite suite(argc, argv);
40  suite.err() << "testing normalizations ... " << std::endl;
41
42  test_centralizer(suite);
43  test_column_normalize(suite);
44  test_quantile_normalize(suite);
45
46  return suite.return_value();
47}
48
49
50void test_centralizer(test::Suite& suite)
51{
52  suite.err() << "Testing Centralizer\n";
53  std::vector<double> vec;
54  vec.push_back(1);
55  vec.push_back(2);
56  vec.push_back(3);
57  normalization::Centralizer<> c;
58  c(vec.begin(), vec.end(), vec.begin());
59  for (size_t i=0; i<vec.size(); ++i)
60    suite.add(suite.equal(vec[i], static_cast<double>(i)-1.0));
61}
62
63
64void test_column_normalize(test::Suite& suite)
65{
66  using namespace normalization;
67  suite.err() << "Testing ColumnNormalizer\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  ColumnNormalizer<Centralizer<> > qn;
75  qn(m, m);
76  suite.err() << "Testing m(0,0)\n";
77  suite.add(suite.equal(m(0,0), -1));
78  suite.err() << "Testing m(0,1)\n";
79  suite.add(suite.equal(m(0,1), 3));
80  suite.err() << "Testing m(1,0)\n";
81  suite.add(suite.equal(m(1,0), 1));
82  suite.err() << "Testing m(1,1)\n";
83  suite.add(suite.equal(m(1,1), -3));
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.