00001 #ifndef _theplu_yat_normalizer_centralizer_
00002 #define _theplu_yat_normalizer_centralizer_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "yat/statistics/Average.h"
00027 #include "yat/utility/DataIterator.h"
00028 #include "yat/utility/iterator_traits.h"
00029 #include "yat/utility/WeightIterator.h"
00030
00031 #include <algorithm>
00032 #include <functional>
00033
00034 namespace theplu {
00035 namespace yat {
00036 namespace normalizer {
00037
00048 template<class UnaryFunction = statistics::Average>
00049 class Centralizer
00050 {
00051 public:
00058 Centralizer(void){}
00059
00063 Centralizer(const UnaryFunction& uf)
00064 : func_(uf) {}
00065
00078 template<class InputIterator, class OutputIterator>
00079 void operator()(InputIterator first, InputIterator last,
00080 OutputIterator result) const
00081 {
00082 typename utility::weighted_iterator_traits<InputIterator>::type tag;
00083 normalize(first, last, result, tag);
00084 }
00085
00086 private:
00087 UnaryFunction func_;
00088
00089
00090 template<class InputIterator, class OutputIterator>
00091 void normalize(InputIterator first,InputIterator last,OutputIterator result,
00092 utility::unweighted_iterator_tag tag) const
00093 {
00094 std::transform(first, last, result,
00095 std::bind2nd(std::minus<double>(), func_(first, last)));
00096 }
00097
00098
00099
00100 template<class InputIterator, class OutputIterator>
00101 void normalize(InputIterator first,InputIterator last,OutputIterator result,
00102 utility::weighted_iterator_tag tag) const
00103 {
00104 std::copy(utility::weight_iterator(first),
00105 utility::weight_iterator(last),
00106 utility::weight_iterator(result));
00107 std::transform(utility::data_iterator(first),
00108 utility::data_iterator(last),
00109 utility::data_iterator(result),
00110 std::bind2nd(std::minus<double>(),func_(first, last)));
00111 }
00112
00113 };
00114
00115 }}}
00116 #endif