source: trunk/yat/normalizer/Zscore.h @ 1521

Last change on this file since 1521 was 1521, checked in by Peter, 15 years ago

Adding a Zscore normalizer

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1#ifndef _theplu_yat_normalizer_z_score_
2#define _theplu_yat_normalizer_z_score_
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 "yat/statistics/Averager.h"
24
25namespace theplu {
26namespace yat {
27namespace normalizer {
28
29  /**
30     \brief Zero mean and unity variance
31
32     Create a range that has zero mean and unity variance
33
34     \since New in yat 0.5
35   */
36  class Zscore
37  {
38  public:
39    /**
40       The element in range [result, result + (last-first)) is
41       calculated as result[i] = (first[i] - m) / std where m and std
42       are the mean and standard deviation, respectively, of the range
43       [first, last).
44
45       It is possible to centralize a range "in place"; it is
46       permissible for the iterators \a first and \a result to be the
47       same. \see std::transform
48
49       \return result + (last-first)
50     */
51    template<class InputIterator, class OutputIterator>
52    OutputIterator operator()(InputIterator first, InputIterator last,
53                              OutputIterator result) const
54    {
55      statistics::Averager a;
56      add(a, first, last);
57      double m = a.mean();
58      double std = a.std();
59      while (first!=last) {
60        *result = (*first - m) / std;
61        ++first;
62        ++result;
63      }
64      return result;
65    }
66
67  };
68
69}}} // end of namespace normalizer, yat and thep
70#endif
Note: See TracBrowser for help on using the repository browser.