1 | #ifndef _theplu_yat_normalizer_gauss_ |
---|
2 | #define _theplu_yat_normalizer_gauss_ |
---|
3 | |
---|
4 | // $Id: Gauss.h 3330 2014-10-14 08:03:25Z peter $ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
---|
8 | Copyright (C) 2009, 2010, 2014 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 | - \c RandomAccessIter1 is \readable_iterator |
---|
62 | - \c RandomAccessIter1 is \random_access_traversal_iterator |
---|
63 | - \c RandomAccessIter1 is \ref concept_data_iterator |
---|
64 | - \c RandomAccessIter2 is \readable_iterator |
---|
65 | - \c RandomAccessIter2 is \writable_iterator |
---|
66 | - \c RandomAccessIter2 is \random_access_traversal_iterator |
---|
67 | - \c RandomAccessIter2 is \ref concept_data_iterator |
---|
68 | |
---|
69 | \see gsl_cdf_ugaussian_Pinv |
---|
70 | */ |
---|
71 | template<typename RandomAccessIter1, typename RandomAccessIter2> |
---|
72 | void operator()(RandomAccessIter1 first, RandomAccessIter1 last, |
---|
73 | RandomAccessIter2 result) const |
---|
74 | { |
---|
75 | Spearman spearman; |
---|
76 | spearman(first, last, result); |
---|
77 | RandomAccessIter2 end = result + std::distance(first, last); |
---|
78 | utility::iterator_traits<RandomAccessIter2> trait; |
---|
79 | while (result != end) { |
---|
80 | trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result)); |
---|
81 | ++result; |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | private: |
---|
87 | }; |
---|
88 | |
---|
89 | }}} // end of namespace normalizer, yat and thep |
---|
90 | #endif |
---|