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 <boost/concept_check.hpp>
00032
00033 #include <algorithm>
00034 #include <functional>
00035
00036 namespace theplu {
00037 namespace yat {
00038 namespace normalizer {
00039
00050 template<class UnaryFunction = statistics::Average>
00051 class Centralizer
00052 {
00053 public:
00060 Centralizer(void){}
00061
00065 Centralizer(const UnaryFunction& uf)
00066 : func_(uf) {}
00067
00080 template<class InputIterator, class OutputIterator>
00081 void operator()(InputIterator first, InputIterator last,
00082 OutputIterator result) const
00083 {
00084 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
00085 typename utility::weighted_iterator_traits<InputIterator>::type tag;
00086 normalize(first, last, result, tag);
00087 }
00088
00089 private:
00090 UnaryFunction func_;
00091
00092
00093 template<class InputIterator, class OutputIterator>
00094 void normalize(InputIterator first,InputIterator last,OutputIterator result,
00095 utility::unweighted_iterator_tag tag) const
00096 {
00097 std::transform(first, last, result,
00098 std::bind2nd(std::minus<double>(), func_(first, last)));
00099 }
00100
00101
00102
00103 template<class InputIterator, class OutputIterator>
00104 void normalize(InputIterator first,InputIterator last,OutputIterator result,
00105 utility::weighted_iterator_tag tag) const
00106 {
00107 std::copy(utility::weight_iterator(first),
00108 utility::weight_iterator(last),
00109 utility::weight_iterator(result));
00110 std::transform(utility::data_iterator(first),
00111 utility::data_iterator(last),
00112 utility::data_iterator(result),
00113 std::bind2nd(std::minus<double>(),func_(first, last)));
00114 }
00115
00116 };
00117
00118 }}}
00119 #endif