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

Last change on this file since 1703 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • 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 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2004, 2005 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
6  Copyright (C) 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 <cassert>
28#include <utility>
29
30namespace theplu {
31namespace yat {
32namespace statistics {
33
34  AveragerPair::AveragerPair(void)
35    : x_(Averager()), y_(Averager()), xy_(0.0)
36  {
37  }
38
39  AveragerPair::AveragerPair(const AveragerPair& a)
40    : x_(a.x_averager()), y_(a.y_averager()), xy_(a.sum_xy())
41  {
42  }
43
44  void AveragerPair::add(const double x, const double y, const long n)
45  {
46    x_.add(x,n); y_.add(y,n); xy_ += n*x*y;
47  }
48
49  double AveragerPair::ccc(void) const
50  {
51    return ((2*covariance()) /
52            ((x_.variance()+y_.variance()) +
53             (x_.mean()-y_.mean())*(x_.mean()-y_.mean())));
54  }
55
56  double AveragerPair::correlation(void) const
57  { return covariance() / std::sqrt(x_.variance()*y_.variance());
58  }
59
60  double AveragerPair::covariance(void) const
61  {
62    return (xy_ - x_.sum_x()*y_.mean()) / n();
63  }
64
65  double AveragerPair::mean_xy(void) const
66  {
67    return xy_/n();
68  }
69
70  double AveragerPair::msd(void) const
71  {
72    return sum_squared_deviation()/n();
73  }
74
75  long AveragerPair::n(void) const
76  {
77    return x_.n();
78  }
79
80  void AveragerPair::reset(void)
81  {
82    x_.reset(); y_.reset(); xy_=0.0;
83  }
84
85  const AveragerPair& AveragerPair::operator=(const AveragerPair& a)
86  {
87    x_=a.x_; y_=a.y_; xy_=a.xy_;
88    return *this;
89  }
90
91  double AveragerPair::sum_squared_deviation(void) const
92  {
93    return x_averager().sum_xx()+y_averager().sum_xx()-2*sum_xy() ;
94  }
95
96  double AveragerPair::sum_xy(void) const
97  {
98    return xy_;
99  }
100
101  double AveragerPair::sum_xy_centered(void) const
102  {
103    return xy_-x_.sum_x()*y_.mean();
104  }
105
106  const Averager& AveragerPair::x_averager(void) const
107  {
108    return x_;
109  }
110
111  const Averager& AveragerPair::y_averager(void) const
112  {
113    return y_;
114  }
115
116  const AveragerPair& AveragerPair::operator+=(const AveragerPair& a)
117  {
118    x_+=a.x_averager();
119    y_+=a.y_averager();
120    xy_+=a.sum_xy();
121    return *this;
122  }
123
124}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.