yat  0.12.3pre
AveragerPairWeighted.h
1 #ifndef _theplu_yat_statistics_averagerpairweighted_
2 #define _theplu_yat_statistics_averagerpairweighted_
3 
4 // $Id: AveragerPairWeighted.h 2571 2011-09-26 02:25:08Z 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 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 
155  template <class InputIterator1, class InputIterator2>
156  void add(AveragerPairWeighted& ap, InputIterator1 first1,
157  InputIterator1 last1, InputIterator2 first2)
158  {
159  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
160  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
163  for ( ; first1 != last1; ++first1, ++first2) {
164  ap.add(traits1.data(first1), traits2.data(first2),
165  traits1.weight(first1), traits2.weight(first2));
166  }
167  }
168 
169 
177  template <typename InputIterator1, typename InputIterator2
178  , typename InputIterator3, typename InputIterator4>
179  void add(AveragerPairWeighted& ap, InputIterator1 x, InputIterator1 xlast,
180  InputIterator2 y, InputIterator3 wx, InputIterator4 wy)
181  {
182  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator1>));
183  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator2>));
184  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator3>));
185  BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator4>));
190  while (x!=xlast) {
191  ap.add(*x, *y, *wx, *wy);
192  ++x;
193  ++y;
194  ++wx;
195  ++wy;
196  }
197  }
198 
199 
200 }}} // of namespace statistics, yat, and theplu
201 
202 #endif
data_reference data(Iter iter) const
Definition: iterator_traits.h:434
Definition: iterator_traits.h:406
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:65
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:156
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:194
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:440
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:179
void reset(void)
Reset everything to zero.

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5