source: branches/0.4-stable/yat/statistics/AveragerPair.cc @ 1294

Last change on this file since 1294 was 1294, checked in by Jari Häkkinen, 15 years ago

Reverting changes that break the interface of Averager and AveragerPair? classes.

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