NAMD
Public Member Functions | List of all members
RunningAverage Class Reference

#include <Controller.h>

Public Member Functions

 RunningAverage ()
 
void add_sample (double x)
 
double average () const
 
double variance () const
 
double standard_deviation () const
 

Detailed Description

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.Calculate running average and standard deviation. Supplement timing output statements with average performance. Implements stable and easily verified recurrence relations from https://en.wikipedia.org/wiki/Standard_deviation

Definition at line 23 of file Controller.h.

Constructor & Destructor Documentation

◆ RunningAverage()

RunningAverage::RunningAverage ( )
inline

Definition at line 28 of file Controller.h.

28 : a(0), q(0), n(0) { }

Member Function Documentation

◆ add_sample()

void RunningAverage::add_sample ( double  x)
inline

Definition at line 29 of file Controller.h.

Referenced by Controller::printTiming().

29  {
30  double a_old = a;
31  n++;
32  a = a_old + (x - a_old) / n;
33  q = q + (x - a_old) * (x - a);
34  }

◆ average()

double RunningAverage::average ( ) const
inline

Definition at line 35 of file Controller.h.

Referenced by Controller::printTiming().

35 { return a; }

◆ standard_deviation()

double RunningAverage::standard_deviation ( ) const
inline

Definition at line 39 of file Controller.h.

References variance().

Referenced by Controller::printTiming().

39 { return sqrt(variance()); }
double variance() const
Definition: Controller.h:38

◆ variance()

double RunningAverage::variance ( ) const
inline

For calculating sample variance, divide by n-1.

Definition at line 38 of file Controller.h.

Referenced by standard_deviation().

38 { return (n > 1 ? q/(n-1) : 0); }

The documentation for this class was generated from the following file: