Changeset 2565
 Timestamp:
 Sep 26, 2011, 2:53:48 AM (11 years ago)
 Location:
 trunk/yat/statistics
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/AveragerPair.cc
r2119 r2565 25 25 #include "Averager.h" 26 26 27 #include <limits> 27 28 #include <utility> 28 29 … … 32 33 33 34 AveragerPair::AveragerPair(void) 34 : x _(Averager()), y_(Averager()), xy_(0.0)35 : xy_centered_(0.0) 35 36 { 36 37 } 37 38 39 38 40 AveragerPair::AveragerPair(const AveragerPair& a) 39 : x_(a.x_ averager()), y_(a.y_averager()), xy_(a.sum_xy())41 : x_(a.x_), y_(a.y_), xy_centered_(a.xy_centered_) 40 42 { 41 43 } 42 44 45 43 46 void AveragerPair::add(const double x, const double y, const long n) 44 47 { 45 x_.add(x,n); y_.add(y,n); xy_ += n*x*y; 48 xy_add(x, y, 0, n); 49 x_.add(x,n); 50 y_.add(y,n); 46 51 } 52 47 53 48 54 double AveragerPair::ccc(void) const … … 53 59 } 54 60 61 55 62 double AveragerPair::correlation(void) const 56 { return covariance() / std::sqrt(x_.variance()*y_.variance()); 63 { 64 return covariance() / std::sqrt(x_.variance()*y_.variance()); 57 65 } 66 58 67 59 68 double AveragerPair::covariance(void) const 60 69 { 61 return (xy_  x_.sum_x()*y_.mean())/ n();70 return xy_centered_ / n(); 62 71 } 72 63 73 64 74 double AveragerPair::mean_xy(void) const 65 75 { 66 return xy_/n(); 76 if (!n()) 77 return std::numeric_limits<double>::quiet_NaN(); 78 return sum_xy()/n(); 67 79 } 80 68 81 69 82 double AveragerPair::msd(void) const … … 72 85 } 73 86 87 74 88 long AveragerPair::n(void) const 75 89 { … … 77 91 } 78 92 93 79 94 void AveragerPair::reset(void) 80 95 { 81 x_.reset(); y_.reset(); xy_=0.0; 96 x_.reset(); 97 y_.reset(); 98 xy_centered_ = 0.0; 82 99 } 100 83 101 84 102 const AveragerPair& AveragerPair::operator=(const AveragerPair& a) 85 103 { 86 x_=a.x_; y_=a.y_; xy_ =a.xy_;104 x_=a.x_; y_=a.y_; xy_centered_=a.xy_centered_; 87 105 return *this; 88 106 } 107 89 108 90 109 double AveragerPair::sum_squared_deviation(void) const … … 93 112 } 94 113 114 95 115 double AveragerPair::sum_xy(void) const 96 116 { 97 return xy_ ;117 return xy_centered_ + x_.sum_x()*y_.mean();; 98 118 } 119 99 120 100 121 double AveragerPair::sum_xy_centered(void) const 101 122 { 102 return xy_ x_.sum_x()*y_.mean();123 return xy_centered_; 103 124 } 125 126 127 void AveragerPair::xy_add(double mx, double my, double xy_centered, long n) 128 { 129 if (!n) 130 return; 131 /* 132 For derivation of update formula refer to 133 http://www.janinebennett.org/index_files/ParallelStatisticsAlgorithms.pdf 134 */ 135 xy_centered_ += xy_centered; 136 if (this>n()) 137 xy_centered_ += static_cast<double>(n*this>n()) / (n+this>n()) * 138 (mxx_.mean()) * (myy_.mean()); 139 140 } 141 104 142 105 143 const Averager& AveragerPair::x_averager(void) const … … 108 146 } 109 147 148 110 149 const Averager& AveragerPair::y_averager(void) const 111 150 { … … 113 152 } 114 153 154 115 155 const AveragerPair& AveragerPair::operator+=(const AveragerPair& a) 116 156 { 157 xy_add(a.x_averager().mean(), a.y_averager().mean(), a.xy_centered_,a.n()); 117 158 x_+=a.x_averager(); 118 159 y_+=a.y_averager(); 119 xy_+=a.sum_xy();120 160 return *this; 121 161 } 
trunk/yat/statistics/AveragerPair.h
r2506 r2565 8 8 Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér 9 9 Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson 10 Copyright (C) 2009, 2010 Peter Johansson10 Copyright (C) 2009, 2010, 2011 Peter Johansson 11 11 12 12 This file is part of the yat library, http://dev.thep.lu.se/yat … … 149 149 Averager x_; 150 150 Averager y_; 151 double xy_ ;151 double xy_centered_; 152 152 153 void xy_add(double mx, double my, double xy_centered, long n); 153 154 }; 154 155
Note: See TracChangeset
for help on using the changeset viewer.