source: trunk/test/normalization_test.cc @ 1497

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

changing name to normalizer - closes #416

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1// $Id: normalization_test.cc 1497 2008-09-12 18:30:41Z 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 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/normalizer/Centralizer.h"
25#include "yat/normalizer/ColumnNormalizer.h"
26#include "yat/normalizer/QuantileNormalizer.h"
27#include "yat/normalizer/Spearman.h"
28
29#include "yat/utility/Matrix.h"
30
31#include <vector>
32
33using namespace theplu::yat;
34void test_centralizer(test::Suite&);
35void test_column_normalize(test::Suite&);
36void test_quantile_normalize(test::Suite&);
37void test_spearman(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  test_spearman(suite);
48
49  return suite.return_value();
50}
51
52
53void test_centralizer(test::Suite& suite)
54{
55  suite.err() << "Testing Centralizer\n";
56  std::vector<double> vec;
57  vec.push_back(1);
58  vec.push_back(2);
59  vec.push_back(3);
60  normalizer::Centralizer<> c;
61  c(vec.begin(), vec.end(), vec.begin());
62  for (size_t i=0; i<vec.size(); ++i)
63    suite.add(suite.equal(vec[i], static_cast<double>(i)-1.0));
64}
65
66
67void test_column_normalize(test::Suite& suite)
68{
69  using namespace normalizer;
70  suite.err() << "Testing ColumnNormalizer\n";
71 
72  utility::Matrix m(2,2);
73  m(0,0) = 0;
74  m(0,1) = 10;
75  m(1,0) = 2;
76  m(1,1) = 4;
77  ColumnNormalizer<Centralizer<> > qn;
78  qn(m, m);
79  suite.err() << "Testing m(0,0)\n";
80  suite.add(suite.equal(m(0,0), -1));
81  suite.err() << "Testing m(0,1)\n";
82  suite.add(suite.equal(m(0,1), 3));
83  suite.err() << "Testing m(1,0)\n";
84  suite.add(suite.equal(m(1,0), 1));
85  suite.err() << "Testing m(1,1)\n";
86  suite.add(suite.equal(m(1,1), -3));
87}
88
89void test_quantile_normalize(test::Suite& suite)
90{
91  suite.err() << "Testing QuantileNormalizer\n";
92 
93  utility::Matrix m(2,2);
94  m(0,0) = 0;
95  m(0,1) = 10;
96  m(1,0) = 2;
97  m(1,1) = 4;
98  normalizer::QuantileNormalizer qn;
99  qn(m, m);
100  suite.err() << "Testing m(0,0)\n";
101  suite.add(suite.equal(m(0,0), 2));
102  suite.err() << "Testing m(0,1)\n";
103  suite.add(suite.equal(m(0,1), 6));
104  suite.err() << "Testing m(1,0)\n";
105  suite.add(suite.equal(m(1,0), 6));
106  suite.err() << "Testing m(1,1)\n";
107  suite.add(suite.equal(m(1,1), 2));
108}
109
110void test_spearman(test::Suite& suite)
111{
112  suite.err() << "Testing Spearman\n";
113  normalizer::Spearman spearman;
114  std::vector<double> vec;
115  vec.push_back(0);
116  vec.push_back(2);
117  vec.push_back(3);
118  vec.push_back(1);
119  spearman(vec.begin(), vec.end(), vec.begin());
120  std::vector<double> correct;
121  correct.push_back(0);
122  correct.push_back(0.5);
123  correct.push_back(0.75);
124  correct.push_back(0.25);
125  suite.equal_range(vec.begin(), vec.end(), correct.begin());
126}
Note: See TracBrowser for help on using the repository browser.