1 | #ifndef _theplu_yat_normalizer_gauss_ |
---|
2 | #define _theplu_yat_normalizer_gauss_ |
---|
3 | |
---|
4 | /* |
---|
5 | Copyright (C) 2008 Peter Johansson |
---|
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 "Spearman.h" |
---|
24 | #include "yat/utility/iterator_traits.h" |
---|
25 | |
---|
26 | #include <gsl/gsl_cdf.h> |
---|
27 | |
---|
28 | namespace theplu { |
---|
29 | namespace yat { |
---|
30 | namespace normalizer { |
---|
31 | |
---|
32 | /** |
---|
33 | \brief Gaussian Normalizer |
---|
34 | |
---|
35 | \since New in yat 0.5 |
---|
36 | */ |
---|
37 | class Gauss |
---|
38 | { |
---|
39 | public: |
---|
40 | /** |
---|
41 | It is possible to centralize a range "in place"; it is |
---|
42 | permissible for the iterators \a first and \a result to be the |
---|
43 | same. |
---|
44 | |
---|
45 | The range is first rank normalized using Spearman, after which |
---|
46 | each element is between 0 and unity. Second each element is |
---|
47 | replaced by inverse cumulative standard Gaussian distribution. |
---|
48 | |
---|
49 | After normalization the range will follow a standard Gaussian |
---|
50 | distribution (mean zero and unity variance). |
---|
51 | |
---|
52 | \see gsl_cdf_ugaussian_Pinv |
---|
53 | |
---|
54 | \return result + (last-first) |
---|
55 | */ |
---|
56 | template<typename ForwardIterator, typename RandomAccessIterator> |
---|
57 | RandomAccessIterator operator()(ForwardIterator first, ForwardIterator last, |
---|
58 | RandomAccessIterator result) const |
---|
59 | { |
---|
60 | Spearman spearman; |
---|
61 | spearman(first, last, result); |
---|
62 | RandomAccessIterator end = result + (last-first); |
---|
63 | utility::iterator_traits<RandomAccessIterator> trait; |
---|
64 | while (result != end) { |
---|
65 | trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result)); |
---|
66 | ++result; |
---|
67 | } |
---|
68 | |
---|
69 | return result; |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | private: |
---|
74 | }; |
---|
75 | |
---|
76 | }}} // end of namespace normalizer, yat and thep |
---|
77 | #endif |
---|