#ifndef _theplu_yat_normalizer_z_score_
#define _theplu_yat_normalizer_z_score_
/*
Copyright (C) 2008 Peter Johansson
This file is part of the yat library, http://dev.thep.lu.se/yat
The yat library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
The yat library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with yat. If not, see .
*/
#include "yat/statistics/Averager.h"
namespace theplu {
namespace yat {
namespace normalizer {
/**
\brief Zero mean and unity variance
Create a range that has zero mean and unity variance
\since New in yat 0.5
*/
class Zscore
{
public:
/**
The element in range [result, result + (last-first)) is
calculated as result[i] = (first[i] - m) / std where m and std
are the mean and standard deviation, respectively, of the range
[first, last).
It is possible to centralize a range "in place"; it is
permissible for the iterators \a first and \a result to be the
same. \see std::transform
\return result + (last-first)
*/
template
OutputIterator operator()(InputIterator first, InputIterator last,
OutputIterator result) const
{
statistics::Averager a;
add(a, first, last);
double m = a.mean();
double std = a.std();
while (first!=last) {
*result = (*first - m) / std;
++first;
++result;
}
return result;
}
};
}}} // end of namespace normalizer, yat and thep
#endif