#include <nNetwork.h>
Public Member Functions | |
nAverager () | |
constructor | |
~nAverager () | |
destructor | |
REAL | GetAverage () const |
returns the average value | |
REAL | GetDataVariance () const |
returns the variance of the data ( average of (value-average)^2 ) | |
REAL | GetAverageVariance () const |
returns the expected variance of the returned average | |
void | Timestep (REAL decay) |
lets all values decay, so they can be replaced by new ones | |
void | Add (REAL value, REAL weight=1) |
adds a value to the average | |
void | Reset () |
resets average to zero | |
std::istream & | operator<< (std::istream &stream) |
read operator | |
std::ostream & | operator>> (std::ostream &stream) const |
write operator | |
Private Attributes | |
REAL | weight_ |
the total statistical weight | |
REAL | sum_ |
the total sum of value*weight | |
REAL | sumSquared_ |
the total sum of value*value*weight | |
REAL | weightSquared_ |
the sum of all weights, squared |
Definition at line 241 of file nNetwork.h.
nAverager::nAverager | ( | void | ) |
constructor
Definition at line 3596 of file nNetwork.cpp.
03600 : weight_(0), sum_(0), sumSquared_(0), weightSquared_(0)
nAverager::~nAverager | ( | void | ) |
REAL nAverager::GetAverage | ( | void | ) | const |
returns the average value
Definition at line 3679 of file nNetwork.cpp.
Referenced by eTimer::AverageFPS(), eTimer::AverageFrameTime(), eTimer::IsSynced(), eTimer::Reset(), and eTimer::SyncTime().
REAL nAverager::GetDataVariance | ( | void | ) | const |
returns the variance of the data ( average of (value-average)^2 )
Definition at line 3697 of file nNetwork.cpp.
Referenced by GameLoop(), and gCycleMovement::TimestepCore().
03701 { 03702 if ( weight_ > 0 ) 03703 { 03704 REAL average = sum_ / weight_; 03705 REAL averageSquare = sumSquared_ / weight_; 03706 REAL ret = averageSquare - average * average; 03707 if ( ret < 0 ) 03708 ret = 0; 03709 return ret; 03710 }
REAL nAverager::GetAverageVariance | ( | void | ) | const |
returns the expected variance of the returned average
Definition at line 3722 of file nNetwork.cpp.
Referenced by eTimer::IsSynced(), eTimer::ReadSync(), sn_GetTimeout(), and eTimer::SyncTime().
03726 { 03727 if ( weight_ > 0 ) 03728 { 03729 REAL square = weight_ * weight_; 03730 03731 REAL denominator = square - weightSquared_; 03732 REAL numerator = GetDataVariance() * weightSquared_; 03733 if ( denominator > numerator * 1E-30 ) 03734 { 03735 return numerator/denominator; 03736 } 03737 else 03738 return 1E+30; 03739 }
void nAverager::Timestep | ( | REAL | decay | ) |
lets all values decay, so they can be replaced by new ones
decay | decay factor 0 .. infinity; larger values lead to more decay. |
Definition at line 3624 of file nNetwork.cpp.
Referenced by eTimer::ReadSync(), and eTimer::SyncTime().
03628 { 03629 REAL factor = 1/(1+decay); 03630 03631 // pretend all data so far was collected with a weight of the original weight multiplied by factor 03632 weight_ *= factor; 03633 sum_ *= factor;
adds a value to the average
value | the value to add | |
weight | its statistical weight (importance compared to other values) |
Definition at line 3646 of file nNetwork.cpp.
Referenced by eTimer::eTimer(), eTimer::ReadSync(), eTimer::Reset(), and eTimer::SyncTime().
void nAverager::Reset | ( | void | ) |
resets average to zero
Definition at line 3664 of file nNetwork.cpp.
Referenced by eTimer::eTimer(), eTimer::ReadSync(), and eTimer::Reset().
std::istream & nAverager::operator<< | ( | std::istream & | stream | ) |
read operator
stream | stream to read from |
Definition at line 3752 of file nNetwork.cpp.
03756 { 03757 char c; 03758 stream >> c; 03759 tASSERT( c == '(' ); 03760 03761 stream >> weight_ >> sum_ >> sumSquared_ >> weightSquared_; 03762 03763 stream >> c; 03764 tASSERT( c == ')' );
std::ostream & nAverager::operator>> | ( | std::ostream & | stream | ) | const |
write operator
stream | stream to write to |
Definition at line 3777 of file nNetwork.cpp.
03781 { 03782 stream << '(' << weight_ << ' ' << sum_ << ' ' << sumSquared_ << ' ' << weightSquared_ << ')';
REAL nAverager::weight_ [private] |
REAL nAverager::sum_ [private] |
REAL nAverager::sumSquared_ [private] |
REAL nAverager::weightSquared_ [private] |