source: trunk/yat/normalizer/QuantileNormalizer.cc @ 1703

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

speeding up QuantileNormalizer? by avoiding some copying and by only sorting each column once and not twice as before.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: QuantileNormalizer.cc 1519 2008-09-21 04:35:39Z peter $
2
3/*
4  Copyright (C) 2005, 2006 Jari Häkkinen, Markus Ringnér
5  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
6  Copyright (C) 2008 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 "QuantileNormalizer.h"
25
26#include "yat/statistics/Averager.h"
27
28#include "yat/utility/Matrix.h"
29#include "yat/utility/VectorConstView.h"
30
31#include <cassert>
32
33namespace theplu {
34namespace yat {
35namespace normalizer {
36
37  void QuantileNormalizer::operator()(const utility::Matrix& data,
38                                      utility::Matrix& result) const
39  {
40    assert(data.rows()==result.rows());
41    assert(data.columns()==result.columns());
42
43    std::vector<std::vector<size_t> > index(data.rows());
44    for (size_t column=0; column<data.columns(); ++column)
45      utility::sort_index(index[column], data.column_const_view(column));
46     
47    for (size_t rank=0; rank<data.rows(); ++rank) {
48      statistics::Averager a;
49      for (size_t column=0; column<data.columns(); ++column)
50        a.add(data(index[column][rank], column));
51      double mean = a.mean();
52      for (size_t column=0; column<data.columns(); ++column)
53        result(index[column][rank], column) = mean;
54    }
55  }
56
57
58
59}}} // end of namespace utility, yat and thep
Note: See TracBrowser for help on using the repository browser.