diff options
Diffstat (limited to 'quantity.hpp')
-rw-r--r-- | quantity.hpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/quantity.hpp b/quantity.hpp index 296a6e8..400a0dd 100644 --- a/quantity.hpp +++ b/quantity.hpp @@ -8,16 +8,21 @@ #include <fstream> #include <iomanip> +template <class T> class Quantity { private: - unsigned n; - std::list<double> hist; + uint64_t N; + uint64_t n; + unsigned skip; + std::list<T> hist; double total; double total2; std::vector<double> C; public: - Quantity(unsigned lag) : C(lag) { + Quantity(unsigned lag, unsigned s = 1) : C(lag) { + skip = s; + N = 0; n = 0; total = 0; total2 = 0; @@ -52,19 +57,23 @@ public: hist = {}; } - void add(double x) { - hist.push_front(x); - if (hist.size() > C.size()) { - hist.pop_back(); - unsigned t = 0; - for (double a : hist) { - C[t] += a * x; - t++; + void add(const T& x) { + if (N % skip == 0) { + hist.push_front(x); + if (hist.size() > C.size()) { + hist.pop_back(); + unsigned t = 0; + for (T a : hist) { + C[t] += a * x; + t++; + } + double norm = x * x; + total += sqrt(norm); + total2 += norm; + n++; } - total += x; - total2 += pow(x, 2); - n++; } + N++; } double avg() const { return total / n; } @@ -96,7 +105,7 @@ public: M++; } - return {τtmp, 2.0 * (2.0 * M + 1) * pow(τtmp, 2) / n}; + return {skip * τtmp, skip * 2.0 * (2.0 * M + 1) * pow(τtmp, 2) / n}; } double σ() const { |