yat  0.14.5pre
AveragerPairWeighted.h
1 #ifndef _theplu_yat_statistics_averagerpairweighted_
2 #define _theplu_yat_statistics_averagerpairweighted_
3 
4 // $Id: AveragerPairWeighted.h 3550 2017-01-03 05:41:02Z peter $
5 
6 /*
7  Copyright (C) 2005 Peter Johansson, Markus Ringnér
8  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
10  Copyright (C) 2009, 2010, 2011, 2016 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 "AveragerWeighted.h"
29 
30 #include "yat/utility/iterator_traits.h"
31 #include "yat/utility/yat_assert.h"
32 
33 #include <boost/concept_check.hpp>
34 
35 #include <cmath>
36 #include <stdexcept>
37 
38 namespace theplu{
39 namespace yat{
40 namespace statistics{
57  {
58  public:
59 
64 
70  void add(const double x, const double y,
71  const double wx, const double wy);
72 
80  double correlation(void) const;
81 
86  double covariance(void) const;
87 
91  double msd(void) const;
92 
96  double n(void) const;
97 
101  void reset(void);
102 
106  double sum_w(void) const;
107 
111  double sum_xy(void) const;
112 
117  double sum_xy_centered(void) const;
118 
124  const AveragerWeighted& x_averager(void) const;
125 
131  const AveragerWeighted& y_averager(void) const;
132 
141 
142  private:
143  AveragerWeighted x_; // weighted averager with w = w_x*w_y
144  AveragerWeighted y_; // weighted averager with w = w_x*w_y
145  double wxy_centered_;
146 
147  void xy_add(double mx, double my, double xy_centered, double w);
148  };
149 
161  template <class InputIterator1, class InputIterator2>
162  void add(AveragerPairWeighted& ap, InputIterator1 first1,
163  InputIterator1 last1, InputIterator2 first2)
164  {
165  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator1>));
166  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator1>));
167  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator2>));
168  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator2>));
169 
172  for ( ; first1 != last1; ++first1, ++first2) {
173  ap.add(traits1.data(first1), traits2.data(first2),
174  traits1.weight(first1), traits2.weight(first2));
175  }
176  }
177 
178 
200  template <typename InputIterator1, typename InputIterator2
201  , typename InputIterator3, typename InputIterator4>
202  void add(AveragerPairWeighted& ap, InputIterator1 x, InputIterator1 xlast,
203  InputIterator2 y, InputIterator3 wx, InputIterator4 wy)
204  {
205  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator1>));
206  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator1>));
207  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator2>));
208  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator2>));
209  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator3>));
210  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator3>));
211  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator4>));
212  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<InputIterator4>));
213 
218  while (x!=xlast) {
219  ap.add(*x, *y, *wx, *wy);
220  ++x;
221  ++y;
222  ++wx;
223  ++wy;
224  }
225  }
226 
227 
228 }}} // of namespace statistics, yat, and theplu
229 
230 #endif
data_reference data(Iter iter) const
Definition: iterator_traits.h:440
Concept check for Data Iterator.
Definition: concept_check.h:228
Definition: iterator_traits.h:412
const AveragerWeighted & x_averager(void) const
Class for taking care of mean and covariance of two variables in a weighted manner.
Definition: AveragerPairWeighted.h:56
const AveragerPairWeighted & operator+=(const AveragerPairWeighted &)
Addition assignment operator.
Class to calulate averages with weights.
Definition: AveragerWeighted.h:66
double correlation(void) const
Pearson correlation coefficient.
void add(AveragerPairWeighted &ap, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
adding a ranges of values to AveragerPairWeighted ap
Definition: AveragerPairWeighted.h:162
const AveragerWeighted & y_averager(void) const
void check_iterator_is_unweighted(Iter iter)
check (at compile time) that iterator is unweighted.
Definition: iterator_traits.h:200
AveragerPairWeighted(void)
The default constructor.
void add(const double x, const double y, const double wx, const double wy)
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:446
void add(AveragerPairWeighted &ap, InputIterator1 x, InputIterator1 xlast, InputIterator2 y, InputIterator3 wx, InputIterator4 wy)
adding four ranges of values to AveragerPairWeighted ap
Definition: AveragerPairWeighted.h:202
void reset(void)
Reset everything to zero.

Generated on Tue Sep 26 2017 02:33:29 for yat by  doxygen 1.8.5