source: trunk/yat/statistics/AveragerPair.cc @ 2078

Last change on this file since 2078 was 2078, checked in by Peter, 14 years ago

remove inclusions not needed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1// $Id: AveragerPair.cc 2078 2009-10-07 16:33:56Z peter $
2
3/*
4  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2005 Peter Johansson
6  Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson
7
8  This file is part of the yat library, http://dev.thep.lu.se/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 3 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with yat. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "AveragerPair.h"
25#include "Averager.h"
26
27#include <utility>
28
29namespace theplu {
30namespace yat {
31namespace statistics {
32
33  AveragerPair::AveragerPair(void)
34    : x_(Averager()), y_(Averager()), xy_(0.0)
35  {
36  }
37
38  AveragerPair::AveragerPair(const AveragerPair& a)
39    : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy())
40  {
41  }
42
43  void AveragerPair::add(const double x, const double y, const long n)
44  {
45    x_.add(x,n); y_.add(y,n); xy_ += n*x*y;
46  }
47
48  double AveragerPair::ccc(void) const
49  {
50    return ((2*covariance()) /
51            ((x_.variance()+y_.variance()) +
52             (x_.mean()-y_.mean())*(x_.mean()-y_.mean())));
53  }
54
55  double AveragerPair::correlation(void) const
56  { return covariance() / std::sqrt(x_.variance()*y_.variance());
57  }
58
59  double AveragerPair::covariance(void) const
60  {
61    return (xy_ - x_.sum_x()*y_.mean()) / n();
62  }
63
64  double AveragerPair::mean_xy(void) const
65  {
66    return xy_/n();
67  }
68
69  double AveragerPair::msd(void) const
70  {
71    return sum_squared_deviation()/n();
72  }
73
74  long AveragerPair::n(void) const
75  {
76    return x_.n();
77  }
78
79  void AveragerPair::reset(void)
80  {
81    x_.reset(); y_.reset(); xy_=0.0;
82  }
83
84  const AveragerPair& AveragerPair::operator=(const AveragerPair& a)
85  {
86    x_=a.x_; y_=a.y_; xy_=a.xy_;
87    return *this;
88  }
89
90  double AveragerPair::sum_squared_deviation(void) const
91  {
92    return x_averager().sum_xx()+y_averager().sum_xx()-2*sum_xy() ;
93  }
94
95  double AveragerPair::sum_xy(void) const
96  {
97    return xy_;
98  }
99
100  double AveragerPair::sum_xy_centered(void) const
101  {
102    return xy_-x_.sum_x()*y_.mean();
103  }
104
105  const Averager& AveragerPair::x_averager(void) const
106  {
107    return x_;
108  }
109
110  const Averager& AveragerPair::y_averager(void) const
111  {
112    return y_;
113  }
114
115  const AveragerPair& AveragerPair::operator+=(const AveragerPair& a)
116  {
117    x_+=a.x_averager();
118    y_+=a.y_averager();
119    xy_+=a.sum_xy();
120    return *this;
121  }
122
123}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.