source: trunk/test/normalization_test.cc @ 1469

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

stray trac.thep

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: normalization_test.cc 1469 2008-09-02 17:21:00Z peter $
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 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_normalize(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_column_normalize(suite);
46  test_quantile_normalize(suite);
47
48  return suite.return_value();
49}
50
51
52void test_centralizer(test::Suite& suite)
53{
54  suite.err() << "Testing Centralizer\n";
55  std::vector<double> vec;
56  vec.push_back(1);
57  vec.push_back(2);
58  vec.push_back(3);
59  normalization::Centralizer<> c;
60  c(vec.begin(), vec.end(), vec.begin());
61  for (size_t i=0; i<vec.size(); ++i)
62    suite.add(suite.equal(vec[i], static_cast<double>(i)-1.0));
63}
64
65
66void test_column_normalize(test::Suite& suite)
67{
68  using namespace normalization;
69  suite.err() << "Testing ColumnNormalizer\n";
70 
71  utility::Matrix m(2,2);
72  m(0,0) = 0;
73  m(0,1) = 10;
74  m(1,0) = 2;
75  m(1,1) = 4;
76  ColumnNormalizer<Centralizer<> > qn;
77  qn(m, m);
78  suite.err() << "Testing m(0,0)\n";
79  suite.add(suite.equal(m(0,0), -1));
80  suite.err() << "Testing m(0,1)\n";
81  suite.add(suite.equal(m(0,1), 3));
82  suite.err() << "Testing m(1,0)\n";
83  suite.add(suite.equal(m(1,0), 1));
84  suite.err() << "Testing m(1,1)\n";
85  suite.add(suite.equal(m(1,1), -3));
86}
87
88void test_quantile_normalize(test::Suite& suite)
89{
90  suite.err() << "Testing QuantileNormalizer\n";
91 
92  utility::Matrix m(2,2);
93  m(0,0) = 0;
94  m(0,1) = 10;
95  m(1,0) = 2;
96  m(1,1) = 4;
97  normalization::QuantileNormalizer qn;
98  qn(m, m);
99  suite.err() << "Testing m(0,0)\n";
100  suite.add(suite.equal(m(0,0), 2));
101  suite.err() << "Testing m(0,1)\n";
102  suite.add(suite.equal(m(0,1), 6));
103  suite.err() << "Testing m(1,0)\n";
104  suite.add(suite.equal(m(1,0), 6));
105  suite.err() << "Testing m(1,1)\n";
106  suite.add(suite.equal(m(1,1), 2));
107}
108
Note: See TracBrowser for help on using the repository browser.