yat
0.8.3pre
|
00001 #ifndef _theplu_yat_normalizer_centralizer_ 00002 #define _theplu_yat_normalizer_centralizer_ 00003 00004 // $Id: Centralizer.h 2415 2011-01-22 06:01:31Z peter $ 00005 00006 /* 00007 Copyright (C) 2008 Jari Häkkinen, Peter Johansson 00008 Copyright (C) 2009, 2010, 2011 Peter Johansson 00009 00010 This file is part of the yat library, http://dev.thep.lu.se/yat 00011 00012 The yat library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU General Public License as 00014 published by the Free Software Foundation; either version 3 of the 00015 License, or (at your option) any later version. 00016 00017 The yat library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with yat. If not, see <http://www.gnu.org/licenses/>. 00024 */ 00025 00026 #include "utility.h" 00027 00028 #include "yat/statistics/Average.h" 00029 #include "yat/utility/DataIterator.h" 00030 #include "yat/utility/iterator_traits.h" 00031 #include "yat/utility/WeightIterator.h" 00032 00033 #include <boost/concept_check.hpp> 00034 00035 #include <algorithm> 00036 #include <functional> 00037 00038 namespace theplu { 00039 namespace yat { 00040 namespace normalizer { 00041 00063 template<class UnaryFunction = statistics::Average> 00064 class Centralizer 00065 { 00066 public: 00073 Centralizer(void){} 00074 00078 Centralizer(const UnaryFunction& uf) 00079 : func_(uf) {} 00080 00097 template<class InputIterator, class ForwardIterator> 00098 void operator()(InputIterator first, InputIterator last, 00099 ForwardIterator result) const 00100 { 00101 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>)); 00102 BOOST_CONCEPT_ASSERT((boost::Mutable_ForwardIterator<ForwardIterator>)); 00103 // copy weight if result is weighted 00104 detail::copy_weight_if_weighted(first, last, result); 00105 std::transform(utility::data_iterator(first), 00106 utility::data_iterator(last), 00107 utility::data_iterator(result), 00108 std::bind2nd(std::minus<double>(),func_(first, last))); 00109 } 00110 00111 private: 00112 UnaryFunction func_; 00113 }; 00114 00115 }}} // end of namespace normalizer, yat and thep 00116 #endif