source: branches/0.12-stable/yat/normalizer/QuantileNormalizer.cc @ 3218

Last change on this file since 3218 was 2992, checked in by Peter, 11 years ago

set svndigest:ignore proprty to reflect when files were initially copied from other file (and early history should be ignored). closes #750

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svndigest:ignore set to 1430
File size: 1.8 KB
Line 
1// $Id: QuantileNormalizer.cc 2992 2013-03-03 05:03:44Z 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 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.rows());
46    for (size_t column=0; column<data.columns(); ++column)
47      utility::sort_index(index[column], data.column_const_view(column));
48     
49    for (size_t rank=0; rank<data.rows(); ++rank) {
50      statistics::Averager a;
51      for (size_t column=0; column<data.columns(); ++column)
52        a.add(data(index[column][rank], column));
53      double mean = a.mean();
54      for (size_t column=0; column<data.columns(); ++column)
55        result(index[column][rank], column) = mean;
56    }
57  }
58
59
60
61}}} // end of namespace utility, yat and thep
Note: See TracBrowser for help on using the repository browser.