source: trunk/yat/normalizer/QuantileNormalizer.cc

Last change on this file was 3342, checked in by Peter, 7 years ago

merge 0.12.2 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svndigest:ignore set to 1430
File size: 2.0 KB
Line 
1// $Id: QuantileNormalizer.cc 3342 2014-11-06 05:26:24Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Markus Ringnér
5  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2012, 2014 Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include <config.h>
25
26#include "QuantileNormalizer.h"
27
28#include "yat/statistics/Averager.h"
29
30#include "yat/utility/Matrix.h"
31#include "yat/utility/VectorConstView.h"
32
33#include <cassert>
34
35namespace theplu {
36namespace yat {
37namespace normalizer {
38
39  void QuantileNormalizer::operator()(const utility::Matrix& data,
40                                      utility::Matrix& result) const
41  {
42    assert(data.rows()==result.rows());
43    assert(data.columns()==result.columns());
44
45    std::vector<std::vector<size_t> > index(data.columns());
46    for (size_t column=0; column<data.columns(); ++column) {
47      assert(column<index.size());
48      utility::sort_index(index[column], data.column_const_view(column));
49    }
50
51    for (size_t rank=0; rank<data.rows(); ++rank) {
52      statistics::Averager a;
53      for (size_t column=0; column<data.columns(); ++column) {
54        assert(column<index.size());
55        assert(rank<index[column].size());
56        a.add(data(index[column][rank], column));
57      }
58      double mean = a.mean();
59      for (size_t column=0; column<data.columns(); ++column) {
60        assert(column<index.size());
61        result(index[column][rank], column) = mean;
62      }
63    }
64  }
65
66
67
68}}} // end of namespace utility, yat and thep
Note: See TracBrowser for help on using the repository browser.