#ifndef _theplu_yat_normalization_centralizer_
#define _theplu_yat_normalization_centralizer_
/*
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 2 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
#include "yat/statistics/Average.h"
#include
#include
namespace theplu {
namespace yat {
namespace normalization {
/**
\brief Centralize a range
The center is calculated and then that value is subtracted from
each element. By default the center is defined as the arithmetic
mean, but this can be changed by providing a suitable
UnaryFunction.
\since New in yat 0.5
*/
template
class Centralizer
{
public:
/**
\brief default constructor
Creates a UnaryFunction using default constructor.
*/
Centralizer(void){}
/**
\param uf unary function defining the center.
*/
Centralizer(const UnaryFunction& uf)
: func_(uf) {}
/**
Calculates the center \a c of the range [first, last) using
UnaryFunction. This value, \a c, is then subtracted from each
element in the range [first, last) and assigned to the
corresponding element in range [result, result + (last-first) ).
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
{
return std::transform(first, last,
result, std::bind2nd(std::minus(),
func_(first, last)));
}
private:
UnaryFunction func_;
};
}}} // end of namespace normalization, yat and thep
#endif