diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2020-11-01 17:09:15 +0100 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2020-11-01 17:09:15 +0100 |
commit | 07a5acbdf79153bb505771708202a9a5fc6f98f0 (patch) | |
tree | 2559116a636b6ac1e63866a4d549834ab07c7a27 /quantity.hpp | |
parent | 9f49a50485a395caa57f0335b5af4e88f2fa2e16 (diff) | |
download | code-07a5acbdf79153bb505771708202a9a5fc6f98f0.tar.gz code-07a5acbdf79153bb505771708202a9a5fc6f98f0.tar.bz2 code-07a5acbdf79153bb505771708202a9a5fc6f98f0.zip |
Added correlation code.
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 { |