LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
RunningSum.h
1 #ifndef RUNNING_SUM_H_
2 #define RUNNING_SUM_H_
3 
8 class RunningSum
9 {
10 public:
15  RunningSum(double decayConstant) :
16  decayConstant(decayConstant), runningSum(0)
17  {
18 
19  }
20 
26  double UpdateSum(double x)
27  {
28  runningSum *= decayConstant;
29  runningSum += x;
30  return runningSum * (1 - decayConstant);
31  }
32 
36  void Clear()
37  {
38  runningSum = 0;
39  }
40 
45  void setDecayConstant(double decayConstant)
46  {
47  this->decayConstant = decayConstant;
48  }
49 
50 private:
51  double decayConstant;
52  double runningSum;
53 };
54 
55 #endif