source: trunk/yat/normalizer/qQuantileNormalizer.h @ 1708

Last change on this file since 1708 was 1708, checked in by Jari Häkkinen, 12 years ago

Addresses #425

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
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
25namespace theplu {
26namespace yat {
27namespace utility {
28  class Matrix;
29  class VectorConstView;
30}
31namespace 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 equal sized partitions, i.e., number of
56       internal parts minus 1.
57
58       \note The end partitions are paired together to make part since
59       they are only half size as compared to the other parts.
60    */
61    size_t size(void) const;
62
63  private:
64    utility::Vector average_;
65    utility::Vector index_;
66  };
67
68
69  /**
70     \brief Perform Q-quantile normalization
71
72     After a Q-quantile normalization each column has the same
73     distribution of data (the Q-quantiles are the same). Also, within
74     each column the rank of an element is not changed.
75
76     There is currently no weighted version of qQuantileNormalizer
77
78     The normalization goes like this
79
80     0. Data is not assumed to be sorted.
81     
82     1. Partition the target data in N+1 parts. The ends have half
83     size of the "normal" part size ( = #targetdata/N )
84
85     2. Calculate the arithmetic mean for each part
86
87     3. Do the same for the data to be tranformed (called source
88     here).
89
90     4. For each part, calculate the difference between the target and
91     the source. Now we have N differences d_i.
92
93     5. Create a cubic spline fit to this difference vector d. The
94     resulting curve is used to recalculate all column values.
95
96         I. For values in parts 1 through N-1 we use a cubic spline
97         fit.
98
99         II. For end parts 0 and N linear interpolation is used
100
101    Linear interpolation simply means a translation.
102
103     \since New in yat 0.5
104   */
105  class qQuantileNormalizer
106  {
107  public:
108    /**
109       \brief Documentation please.
110
111       \a Q is the number of parts and must be within \f [2,N] \f
112       where \f N \f is the total number of data points in the
113       target. However, if \f N \f is larger than the number of points
114       in the data to be normalized the behaviour of the code is
115       undefined. Keep \f N \f equal to or less than the smallest
116       number of data points in the target or each data set to be
117       normalized with a ginven target.
118    */
119    qQuantileNormalizer(const utility::VectorConstView& target,
120                        unsigned int Q);
121
122    /**
123       \brief perform the Q-quantile normalization.
124
125       It is possible to normalize "in place"; it is permissible for
126       \a matrix and \a result to reference the same Matrix.
127
128       \note dimensions of \a matrix and \a result must match.
129     */
130    void operator()(const utility::Matrix& matrix,
131                    utility::Matrix& result) const;
132
133  private:
134    Partitioner target_;
135  };
136
137}}} // end of namespace normalizer, yat and thep
138
139#endif
Note: See TracBrowser for help on using the repository browser.