diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-12 18:00:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-08-12 18:00:49 +0200 |
commit | 9040b187a1c4fa380f8a12207b9dd6d04b3a10ac (patch) | |
tree | 115e1351571d690c1261a9d512e6d44e717f3051 /opentrack/variance.hpp | |
parent | 13a18b149764509a3f460be86590250cdcf690fb (diff) |
all: rename modules s#^opentrack-##. and opentrack -> api
Adjust usages.
Diffstat (limited to 'opentrack/variance.hpp')
-rw-r--r-- | opentrack/variance.hpp | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/opentrack/variance.hpp b/opentrack/variance.hpp deleted file mode 100644 index 55060b02..00000000 --- a/opentrack/variance.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include <cmath> - -// no copyright information other than the attribution below. - -// code shared as an example/tutorial of running variance -// written by John D. Cook on the website <http://www.johndcook.com/blog/standard_deviation> - -// following references in the site's article: - -// Chan, Tony F.; Golub, Gene H.; LeVeque, Randall J. (1983). -// Algorithms for Computing the Sample Variance: Analysis and Recommendations. -// The American Statistician 37, 242-247. - -// Ling, Robert F. (1974). -// Comparison of Several Algorithms for Computing Sample Means and Variances. -// Journal of the American Statistical Association, Vol. 69, No. 348, 859-866. - -class variance -{ - double m_old, m_new, s_old, s_new; - unsigned long cnt; - -public: - variance() : cnt(0) {} - - void clear() { *this = variance(); } - - void input(double x) - { - cnt++; - - if (cnt == 1) - { - m_old = m_new = x; - s_old = 0; - } - else - { - m_new = m_old + (x - m_old)/cnt; - s_new = s_old + (x - m_old)*(x - m_new); - - m_old = m_new; - s_old = s_new; - } - } - - double avg() const { return cnt > 0 ? m_new : 0; } - double Var() const { return cnt > 1 ? s_new/(cnt - 1) : 0; } - double stddev() const { return std::sqrt(Var()); } -}; |