source: trunk/yat/normalizer/Gauss.h @ 2148

Last change on this file since 2148 was 2148, checked in by Peter, 13 years ago

fixes #582 and refs #583

Claify that normalizer::Spearman requires random_access_iterator as
input and Gauss inherits the requirement. Added compile test and
concept check for Gauss.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef _theplu_yat_normalizer_gauss_
2#define _theplu_yat_normalizer_gauss_
3
4// $Id: Gauss.h 2148 2010-01-17 03:16:27Z peter $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009 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/iterator_traits.h"
28
29#include <boost/concept_check.hpp>
30
31#include <gsl/gsl_cdf.h>
32
33#include <iterator>
34
35namespace theplu {
36namespace yat {
37namespace normalizer {
38
39  /**
40     \brief Gaussian Normalizer
41
42     After normalization the range will follow a standard Gaussian
43     distribution (mean zero and unity variance).
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     \since New in yat 0.5
50   */
51  class Gauss
52  {
53  public:
54    /**
55       It is possible to centralize a range "in place"; it is
56       permissible for the iterators \a first and \a result to be the
57       same.
58
59       Type requirements:
60       - ForwardIterator must be a \forward_iterator and a \ref
61       concept_data_iterator.
62       - RandomAccessIterator must be a mutable \random_access_iterator
63         and a \ref concept_data_iterator.
64
65       \see gsl_cdf_ugaussian_Pinv
66     */
67    template<typename RandomAccessIter1, typename RandomAccessIter2>
68    void operator()(RandomAccessIter1 first, RandomAccessIter1 last,
69                    RandomAccessIter2 result) const
70    {
71      boost::function_requires<boost::RandomAccessIterator<RandomAccessIter1> >();
72      boost::function_requires<boost::Mutable_RandomAccessIterator<RandomAccessIter2> >();
73      Spearman spearman;
74      spearman(first, last, result);
75      RandomAccessIter2 end = result + std::distance(first, last);
76      utility::iterator_traits<RandomAccessIter2> trait;
77      while (result != end) {
78        trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result));
79        ++result;
80      }
81    }
82
83
84  private:
85  };
86
87}}} // end of namespace normalizer, yat and thep
88#endif
Note: See TracBrowser for help on using the repository browser.