source: trunk/yat/statistics/AveragerPairWeighted.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 Id
File size: 2.4 KB
Line 
1// $Id: AveragerPairWeighted.cc 1487 2008-09-10 08:41:36Z jari $
2
3/*
4  Copyright (C) 2005 Peter Johansson, Markus Ringnér
5  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
6  Copyright (C) 2008 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 "AveragerPairWeighted.h"
25#include "AveragerPair.h"
26#include "Averager.h"
27
28#include <cassert>
29
30namespace theplu {
31namespace yat {
32namespace statistics {
33
34
35  AveragerPairWeighted::AveragerPairWeighted(void)
36    : wxy_(0), w_(0)
37  {
38  }
39
40
41  void  AveragerPairWeighted::add(const double x, const double y, 
42                                  const double wx, const double wy)
43  { 
44    if(wx==0.0 || wy==0.0) {
45      return;
46    }
47    assert(!std::isnan(x) && "x is nan");
48    assert(!std::isnan(y) && "y is nan");
49    assert(!std::isnan(wx) && "wx is nan");
50    assert(!std::isnan(wy) && "wy is nan");
51    double w=wx*wy;
52    x_.add(x,w);
53    y_.add(y,w); 
54    wxy_ += w*x*y;   
55    w_ +=w;
56  }
57
58
59  double AveragerPairWeighted::correlation(void) const
60  {
61    return covariance() / sqrt(x_.variance()*y_.variance());
62  }
63
64
65  double AveragerPairWeighted::covariance(void) const
66  {
67    return sum_xy_centered()/sum_w();
68  }
69
70
71  double AveragerPairWeighted::msd(void) const
72  {
73    return (x_.sum_wxx()+y_.sum_wxx()-2*wxy_)/w_;
74  }
75
76
77  double AveragerPairWeighted::n(void) const
78  {
79    return x_.n();
80  }
81
82
83  void AveragerPairWeighted::reset(void)
84  {
85    x_.reset(); y_.reset(); wxy_=0; w_=0;
86  }
87
88
89  double AveragerPairWeighted::sum_w(void) const
90  {
91    return w_;
92  }
93
94
95  double AveragerPairWeighted::sum_xy(void) const
96  {
97    return wxy_;
98  }
99
100
101  double AveragerPairWeighted::sum_xy_centered(void) const
102  {
103    return sum_xy() - x_.sum_wx()*y_.mean();
104  }
105
106
107  const AveragerWeighted& AveragerPairWeighted::x_averager(void) const
108  {
109    return x_;
110  }
111
112
113  const AveragerWeighted& AveragerPairWeighted::y_averager(void) const
114  {
115    return y_;
116  }
117
118}}} // of namespace statistics, yat, and theplu
Note: See TracBrowser for help on using the repository browser.