1 | #ifndef _theplu_yat_normalizer_qquantile_normalizer_ |
---|
2 | #define _theplu_yat_normalizer_qquantile_normalizer_ |
---|
3 | |
---|
4 | /* |
---|
5 | Copyright (C) 2009 Jari Häkkinen |
---|
6 | |
---|
7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
8 | |
---|
9 | The yat library is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License as |
---|
11 | published by the Free Software Foundation; either version 3 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | The yat library is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | */ |
---|
22 | |
---|
23 | #include "yat/utility/Vector.h" |
---|
24 | |
---|
25 | namespace theplu { |
---|
26 | namespace yat { |
---|
27 | namespace utility { |
---|
28 | class Matrix; |
---|
29 | class VectorConstView; |
---|
30 | } |
---|
31 | namespace normalizer { |
---|
32 | |
---|
33 | /** |
---|
34 | \brief Documentation please. |
---|
35 | */ |
---|
36 | class Partitioner |
---|
37 | { |
---|
38 | public: |
---|
39 | /** |
---|
40 | \brief Documentation please. |
---|
41 | */ |
---|
42 | Partitioner(const utility::VectorConstView& vec, unsigned int N); |
---|
43 | |
---|
44 | /** |
---|
45 | \brief Documentation please. |
---|
46 | */ |
---|
47 | const utility::Vector& averages(void) const; |
---|
48 | |
---|
49 | /** |
---|
50 | \brief Documentation please. |
---|
51 | */ |
---|
52 | const utility::Vector& index(void) const; |
---|
53 | |
---|
54 | /** |
---|
55 | \brief The number of parts. |
---|
56 | */ |
---|
57 | size_t size(void) const; |
---|
58 | |
---|
59 | private: |
---|
60 | utility::Vector average_; |
---|
61 | utility::Vector index_; |
---|
62 | }; |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | \brief Perform Q-quantile normalization |
---|
67 | |
---|
68 | After a Q-quantile normalization each column has the same |
---|
69 | distribution of data (the Q-quantiles are the same). Also, within |
---|
70 | each column the rank of an element is not changed. |
---|
71 | |
---|
72 | There is currently no weighted version of qQuantileNormalizer |
---|
73 | |
---|
74 | The normalization goes like this |
---|
75 | |
---|
76 | 0. Data is not assumed to be sorted. |
---|
77 | |
---|
78 | 1. Partition the target data in N+1 parts. The ends have half |
---|
79 | size of the "normal" part size ( = #targetdata/N ) |
---|
80 | |
---|
81 | 2. Calculate the arithmetic mean for each part |
---|
82 | |
---|
83 | 3. Do the same for the data to be tranformed (called source |
---|
84 | here). |
---|
85 | |
---|
86 | 4. For each part, calculate the difference between the target and |
---|
87 | the source. Now we have N differences d_i. |
---|
88 | |
---|
89 | 5. Create a cubic spline fit to this difference vector d. The |
---|
90 | resulting curve is used to recalculate all column values. |
---|
91 | |
---|
92 | I. For values in parts 1 through N-1 we use a cubic spline |
---|
93 | fit. |
---|
94 | |
---|
95 | II. For end parts 0 and N linear interpolation is used |
---|
96 | |
---|
97 | Linear interpolation simply means a translation. |
---|
98 | |
---|
99 | \since New in yat 0.5 |
---|
100 | */ |
---|
101 | class qQuantileNormalizer |
---|
102 | { |
---|
103 | public: |
---|
104 | /** |
---|
105 | \brief Documentation please. |
---|
106 | |
---|
107 | \a Q is the number of parts and must be within \f [2,N] \f |
---|
108 | where \f N \f is the total number of data points in the |
---|
109 | target. However, if \f N \f is larger than the number of points |
---|
110 | in the data to be normalized the behaviour of the code is |
---|
111 | undefined. Keep \f N \f equal to or less than the smallest |
---|
112 | number of data points in the target or each data set to be |
---|
113 | normalized with a ginven target. |
---|
114 | */ |
---|
115 | qQuantileNormalizer(const utility::VectorConstView& target, |
---|
116 | unsigned int Q); |
---|
117 | |
---|
118 | /** |
---|
119 | \brief perform the Q-quantile normalization. |
---|
120 | |
---|
121 | It is possible to normalize "in place"; it is permissible for |
---|
122 | \a matrix and \a result to reference the same Matrix. |
---|
123 | |
---|
124 | \note dimensions of \a matrix and \a result must match. |
---|
125 | */ |
---|
126 | void operator()(const utility::Matrix& matrix, |
---|
127 | utility::Matrix& result) const; |
---|
128 | |
---|
129 | private: |
---|
130 | Partitioner target_; |
---|
131 | }; |
---|
132 | |
---|
133 | }}} // end of namespace normalizer, yat and thep |
---|
134 | |
---|
135 | #endif |
---|