1 | #ifndef _theplu_yat_normalizer_gauss_ |
---|
2 | #define _theplu_yat_normalizer_gauss_ |
---|
3 | |
---|
4 | // $Id: Gauss.h 3550 2017-01-03 05:41:02Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2009, 2010, 2014, 2016 Peter Johansson |
---|
9 | |
---|
10 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
11 | |
---|
12 | The yat library is free software; you can redistribute it and/or |
---|
13 | modify it under the terms of the GNU General Public License as |
---|
14 | published by the Free Software Foundation; either version 3 of the |
---|
15 | License, or (at your option) any later version. |
---|
16 | |
---|
17 | The yat library is distributed in the hope that it will be useful, |
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
20 | General Public License for more details. |
---|
21 | |
---|
22 | You should have received a copy of the GNU General Public License |
---|
23 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
24 | */ |
---|
25 | |
---|
26 | #include "Spearman.h" |
---|
27 | #include "yat/utility/concept_check.h" |
---|
28 | #include "yat/utility/iterator_traits.h" |
---|
29 | |
---|
30 | #include <boost/concept_check.hpp> |
---|
31 | |
---|
32 | #include <gsl/gsl_cdf.h> |
---|
33 | |
---|
34 | #include <iterator> |
---|
35 | |
---|
36 | namespace theplu { |
---|
37 | namespace yat { |
---|
38 | namespace normalizer { |
---|
39 | |
---|
40 | /** |
---|
41 | \brief Gaussian Normalizer |
---|
42 | |
---|
43 | After normalization the range will follow a standard Gaussian |
---|
44 | distribution (mean zero and unity variance). |
---|
45 | |
---|
46 | The range is first rank normalized using Spearman, after which |
---|
47 | each element is between 0 and unity. Second each element is |
---|
48 | replaced by inverse cumulative standard Gaussian distribution. |
---|
49 | |
---|
50 | \since New in yat 0.5 |
---|
51 | */ |
---|
52 | class Gauss |
---|
53 | { |
---|
54 | public: |
---|
55 | /** |
---|
56 | It is possible to centralize a range "in place"; it is |
---|
57 | permissible for the iterators \a first and \a result to be the |
---|
58 | same. |
---|
59 | |
---|
60 | Type Requirements: |
---|
61 | Same as in Spearman |
---|
62 | |
---|
63 | \see gsl_cdf_ugaussian_Pinv |
---|
64 | */ |
---|
65 | template<typename RandomAccessIter1, typename RandomAccessIter2> |
---|
66 | void operator()(RandomAccessIter1 first, RandomAccessIter1 last, |
---|
67 | RandomAccessIter2 result) const |
---|
68 | { |
---|
69 | Spearman spearman; |
---|
70 | spearman(first, last, result); |
---|
71 | RandomAccessIter2 end = result + std::distance(first, last); |
---|
72 | utility::iterator_traits<RandomAccessIter2> trait; |
---|
73 | while (result != end) { |
---|
74 | trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result)); |
---|
75 | ++result; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | private: |
---|
81 | }; |
---|
82 | |
---|
83 | }}} // end of namespace normalizer, yat and thep |
---|
84 | #endif |
---|