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

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

Adding a Zscore normalizer

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
RevLine 
[1521]1#ifndef _theplu_yat_normalizer_z_score_
2#define _theplu_yat_normalizer_z_score_
[1445]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
[1486]11  published by the Free Software Foundation; either version 3 of the
[1445]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
[1487]20  along with yat. If not, see <http://www.gnu.org/licenses/>.
[1445]21*/
22
[1521]23#include "yat/statistics/Averager.h"
[1445]24
25namespace theplu {
26namespace yat {
[1497]27namespace normalizer {
[1445]28
29  /**
[1521]30     \brief Zero mean and unity variance
[1445]31
[1521]32     Create a range that has zero mean and unity variance
[1445]33
34     \since New in yat 0.5
35   */
[1521]36  class Zscore
[1445]37  {
38  public:
39    /**
[1521]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).
[1445]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    {
[1521]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;
[1445]65    }
66
67  };
68
[1497]69}}} // end of namespace normalizer, yat and thep
[1445]70#endif
Note: See TracBrowser for help on using the repository browser.