Changeset 2157 for trunk/yat/normalizer/Zscore.h
- Timestamp:
- Jan 18, 2010, 1:19:52 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/normalizer/Zscore.h
r2119 r2157 24 24 */ 25 25 26 #include "utility.h" 27 26 28 #include "yat/statistics/Averager.h" 27 29 #include "yat/statistics/AveragerWeighted.h" 28 30 29 31 #include "yat/utility/iterator_traits.h" 32 33 #include <boost/concept_check.hpp> 30 34 31 35 namespace theplu { … … 56 60 same. \see std::transform 57 61 */ 58 template<class InputIterator, class OutputIterator>59 void operator()( InputIterator first, InputIteratorlast,60 OutputIteratorresult) const62 template<class ForwardIter1, class ForwardIter2> 63 void operator()(ForwardIter1 first, ForwardIter1 last, 64 ForwardIter2 result) const 61 65 { 62 typename utility::weighted_i terator_traits<InputIterator>::type tag;66 typename utility::weighted_if_any2<ForwardIter1, ForwardIter2>::type tag; 63 67 normalize(first, last, result, tag); 64 68 } 65 69 66 70 private: 67 template<class InputIterator, class OutputIterator> 68 void normalize(InputIterator first,InputIterator last,OutputIterator result, 71 template<class ForwardIterator, class OutputIterator> 72 void normalize(ForwardIterator first, ForwardIterator last, 73 OutputIterator result, 69 74 utility::unweighted_iterator_tag tag) const 70 75 { 76 // we requre forward iterator since we iterate through the range 77 // multiple times. 78 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>)); 79 BOOST_CONCEPT_ASSERT((boost::OutputIterator<OutputIterator, double>)); 71 80 statistics::Averager a; 72 81 add(a, first, last); … … 80 89 } 81 90 82 template<class InputIterator, class OutputIterator>83 void normalize( InputIterator first,InputIterator last,OutputIteratorresult,91 template<class ForwardIter1, class ForwardIter2> 92 void normalize(ForwardIter1 first, ForwardIter1 last, ForwardIter2 result, 84 93 utility::weighted_iterator_tag tag) const 85 94 { 86 std::copy(utility::weight_iterator(first), 87 utility::weight_iterator(last), 88 utility::weight_iterator(result)); 95 // we requre forward iterator since we iterate through the range 96 // multiple times. 97 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIter1>)); 98 BOOST_CONCEPT_ASSERT((boost::Mutable_ForwardIterator<ForwardIter2>)); 99 detail::copy_weight_if_weighted(first, last, result); 89 100 statistics::AveragerWeighted a; 90 101 add(a, first, last); 91 102 double m = a.mean(); 92 103 double std = a.std(); 93 utility::iterator_traits<InputIterator> trait; 104 utility::iterator_traits<ForwardIter1> in_trait; 105 utility::iterator_traits<ForwardIter2> out_trait; 94 106 while (first!=last) { 95 trait.data(result) = (trait.data(first) - m) / std;107 out_trait.data(result) = (in_trait.data(first) - m) / std; 96 108 ++first; 97 109 ++result;
Note: See TracChangeset
for help on using the changeset viewer.