yat/normalizer/Gauss.h

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