1 #ifndef _theplu_yat_statistics_tukey_biweight_estimator 2 #define _theplu_yat_statistics_tukey_biweight_estimator 25 #include "AveragerWeighted.h" 28 #include "yat/regression/TukeyBiweight.h" 30 #include "yat/utility/concept_check.h" 31 #include "yat/utility/Exception.h" 32 #include "yat/utility/iterator_traits.h" 34 #include <boost/concept_check.hpp> 35 #include <boost/iterator/iterator_concepts.hpp> 44 namespace statistics {
77 : cutoff_(cutoff), sorted_(sorted) {}
87 template<
typename RandomAccessIterator>
89 RandomAccessIterator last)
const;
95 template<
typename RandomAccessIterator>
96 double estimate(RandomAccessIterator first,
97 RandomAccessIterator last)
const;
99 template<
typename InputIterator>
100 double estimate(InputIterator first, InputIterator last,
101 double center,
double spread)
const;
104 template<
typename RandomAccessIterator>
106 RandomAccessIterator last)
const 108 using boost_concepts::RandomAccessTraversal;
109 BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIterator>));
111 BOOST_CONCEPT_ASSERT((DataIteratorConcept<RandomAccessIterator>));
114 return estimate(first, last);
117 typedef typename std::iterator_traits<RandomAccessIterator> traits;
118 std::vector<typename traits::value_type> vec(first, last);
119 std::sort(vec.begin(), vec.end());
120 return estimate(vec.begin(), vec.end());
124 template<
typename RandomAccessIterator>
125 double TukeyBiweightEstimator::estimate(RandomAccessIterator first,
126 RandomAccessIterator last)
const 128 const double scale =
mad(first, last,
true);
129 double m =
median(first, last,
true);
140 m = estimate(first, last, m, scale);
150 template<
typename InputIterator>
151 double TukeyBiweightEstimator::estimate(InputIterator first,
153 double center,
double spread)
const 155 double scale = spread*cutoff_;
159 for ( ; first!=last; ++first) {
160 double x = traits.
data(first);
161 double w = traits.
weight(first) * biweight((x-center)/scale);
164 return averager.
mean();
TukeyBiweightEstimator(double cutoff=4.685, bool sorted=false)
Constructor.
Definition: TukeyBiweightEstimator.h:76
double mad(RandomAccessIterator first, RandomAccessIterator last, bool sorted=false)
Median absolute deviation from median.
Definition: utility.h:390
data_reference data(Iter iter) const
Definition: iterator_traits.h:440
double operator()(RandomAccessIterator first, RandomAccessIterator last) const
Definition: TukeyBiweightEstimator.h:105
Concept check for Data Iterator.
Definition: concept_check.h:228
Definition: iterator_traits.h:412
double mean(void) const
Calculate the weighted mean.
The Department of Theoretical Physics namespace as we define it.
Class to calulate averages with weights.
Definition: AveragerWeighted.h:66
void add(const double d, const double w=1)
double median(RandomAccessIterator first, RandomAccessIterator last, bool sorted=false)
Definition: utility.h:413
Class used for all runtime error detected within yat library.
Definition: Exception.h:38
Tukey's Biweight Estimator.
Definition: TukeyBiweightEstimator.h:64
Definition: TukeyBiweight.h:34
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:446
Definition: averager_traits.h:79