1 | // $Id: qQuantileNormalizer.cc 1736 2009-01-19 14:26:49Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2009 Jari Häkkinen, 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 "qQuantileNormalizer.h" |
---|
23 | |
---|
24 | #include "yat/regression/CSplineInterpolation.h" |
---|
25 | #include "yat/statistics/Averager.h" |
---|
26 | #include "yat/utility/Vector.h" |
---|
27 | #include "yat/utility/VectorBase.h" |
---|
28 | |
---|
29 | #include <algorithm> |
---|
30 | #include <cassert> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | namespace normalizer { |
---|
35 | |
---|
36 | |
---|
37 | void |
---|
38 | qQuantileNormalizer::Partitioner::init(const utility::VectorBase& sortedvec, |
---|
39 | unsigned int N) |
---|
40 | { |
---|
41 | assert(N>1); |
---|
42 | assert(N<=sortedvec.size()); |
---|
43 | double range=static_cast<double>(sortedvec.size())/N; |
---|
44 | assert(range); |
---|
45 | unsigned int start=0; |
---|
46 | for (unsigned int i=0; i<N; ++i) { |
---|
47 | unsigned int end = ( i==(N-1) ? sortedvec.size() : |
---|
48 | static_cast<unsigned int>((i+1)*range) ); |
---|
49 | statistics::Averager av; |
---|
50 | for (unsigned int r=start; r<end; ++r) |
---|
51 | av.add(sortedvec(r)); |
---|
52 | average_(i) = av.mean(); |
---|
53 | index_(i) = 0.5*(end+start-1); |
---|
54 | start=end; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | const utility::Vector& qQuantileNormalizer::Partitioner::averages(void) const |
---|
60 | { |
---|
61 | return average_; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | const utility::Vector& qQuantileNormalizer::Partitioner::index(void) const |
---|
66 | { |
---|
67 | return index_; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | size_t qQuantileNormalizer::Partitioner::size(void) const |
---|
72 | { |
---|
73 | return average_.size(); |
---|
74 | } |
---|
75 | |
---|
76 | }}} // end of namespace normalizer, yat and thep |
---|