yat  0.13.2pre
AveragerWeighted.h
1 #ifndef _theplu_yat_statistics_averagerweighted_
2 #define _theplu_yat_statistics_averagerweighted_
3 
4 // $Id: AveragerWeighted.h 2564 2011-09-25 20:03:41Z peter $
5 
6 /*
7  Copyright (C) 2004 Jari Häkkinen, Peter Johansson, Cecilia Ritz
8  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2009, 2010, 2011 Peter Johansson
11 
12  This file is part of the yat library, http://dev.thep.lu.se/yat
13 
14  The yat library is free software; you can redistribute it and/or
15  modify it under the terms of the GNU General Public License as
16  published by the Free Software Foundation; either version 3 of the
17  License, or (at your option) any later version.
18 
19  The yat library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with yat. If not, see <http://www.gnu.org/licenses/>.
26 */
27 
28 #include "yat/utility/iterator_traits.h"
29 
30 #include <boost/concept_check.hpp>
31 
32 #include <cmath>
33 
34 namespace theplu{
35 namespace yat{
36 namespace statistics{
37 
66  {
67  public:
68 
72  AveragerWeighted(void);
73 
78 
82  void add(const double d,const double w=1);
83 
89  double mean(void) const;
90 
102  double n(void) const;
103 
109  void rescale(double a);
110 
114  void reset(void);
115 
122  double std(void) const;
123 
135  double standard_error(void) const;
136 
142  double sum_w(void) const;
143 
147  double sum_ww(void) const;
148 
154  double sum_wx(void) const;
155 
159  double sum_wxx(void) const;
160 
164  double sum_xx_centered(void) const;
165 
172  double variance(const double m) const;
173 
183  double variance(void) const;
184 
191 
192  private:
196  double sum_wwx(void) const;
197 
201  double sum_wwxx(void) const;
202 
203  double mean_; // wx/w
204  double m2_; // wxx - m*m*w
205  double w_;
206  double ww_;
207  double wwxx_;
208  double wxx_;
209 
210  // double wwx; // m2_ + m*m*w
211  // double wx; // w*mean_
212  };
213 
221  template <typename InputIterator>
222  void add(AveragerWeighted& a, InputIterator first, InputIterator last)
223  {
224  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
226  for ( ; first != last; ++first)
227  a.add(traits.data(first), traits.weight(first));
228  }
229 
241  template <typename InputIterator1, typename InputIterator2>
242  void add(AveragerWeighted& a, InputIterator1 first1, InputIterator1 last1,
243  InputIterator2 first2)
244  {
245  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
246  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
249  for ( ; first1 != last1; ++first1, ++first2)
250  a.add(*first1, *first2);
251  }
252 
253 }}} // of namespace statistics, yat, and theplu
254 
255 #endif
data_reference data(Iter iter) const
Definition: iterator_traits.h:440
Definition: iterator_traits.h:412
double mean(void) const
Calculate the weighted mean.
double standard_error(void) const
Calculates standard deviation of the mean().
void add(AveragerWeighted &a, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
add values from two ranges to AveragerWeighted a
Definition: AveragerWeighted.h:242
Class to calulate averages with weights.
Definition: AveragerWeighted.h:65
void add(const double d, const double w=1)
double std(void) const
The standard deviation is defined as the square root of the variance().
double n(void) const
Weighted version of number of data points.
void check_iterator_is_unweighted(Iter iter)
check (at compile time) that iterator is unweighted.
Definition: iterator_traits.h:200
void reset(void)
Reset everything to zero.
const AveragerWeighted & operator+=(const AveragerWeighted &)
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:446
AveragerWeighted(void)
The default constructor.
void add(AveragerWeighted &a, InputIterator first, InputIterator last)
adding a range of values to AveragerWeighted a
Definition: AveragerWeighted.h:222
void rescale(double a)
Rescale object.

Generated on Wed Jan 4 2017 02:23:07 for yat by  doxygen 1.8.5