changes from the laptop
- some should be the same as previous commit (sorry!) - some should be new: LINT checks, ...?
This commit is contained in:
49
math/MovingStdDevTS.h
Normal file
49
math/MovingStdDevTS.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef MOVINGSTDDEVTS_H
|
||||
#define MOVINGSTDDEVTS_H
|
||||
|
||||
#include "MovingAverageTS.h"
|
||||
|
||||
/**
|
||||
* moving stadnard-deviation using a given time-region
|
||||
*/
|
||||
template <typename T> class MovingStdDevTS {
|
||||
|
||||
private:
|
||||
|
||||
MovingAverageTS<T> avg;
|
||||
MovingAverageTS<T> avg2;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/** ctor with the window-size to use */
|
||||
MovingStdDevTS(const Timestamp window, const T zeroElement) : avg(window, zeroElement), avg2(window, zeroElement) {
|
||||
;
|
||||
}
|
||||
|
||||
/** add a new entry */
|
||||
void add(const Timestamp ts, const T& data) {
|
||||
|
||||
// E(x)
|
||||
avg.add(ts, data);
|
||||
|
||||
// E(x^2)
|
||||
avg2.add(ts, data*data);
|
||||
|
||||
}
|
||||
|
||||
/** get the current std-dev */
|
||||
T get() const {
|
||||
|
||||
const T e = avg.get();
|
||||
const T e2 = avg2.get();
|
||||
const T var = e2 - e*e;
|
||||
return std::sqrt(var);
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // MOVINGSTDDEVTS_H
|
||||
Reference in New Issue
Block a user