From d53099d36986ca7207f507f11d8e9552340f210c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 24 May 2017 17:22:30 +0200 Subject: api/variance: move to compat/ --- api/variance.hpp | 57 ----------------------------------------------- compat/variance.hpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++ tracker-hatire/thread.hpp | 2 +- 3 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 api/variance.hpp create mode 100644 compat/variance.hpp diff --git a/api/variance.hpp b/api/variance.hpp deleted file mode 100644 index 7a83154c..00000000 --- a/api/variance.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -// 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 - -// 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; - std::uintptr_t cnt; - -public: - using size_type = std::uintptr_t; - - variance() : cnt(0) {} - - void clear() { *this = variance(); } - - size_type count() { return cnt; } - - 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()); } -}; diff --git a/compat/variance.hpp b/compat/variance.hpp new file mode 100644 index 00000000..7a83154c --- /dev/null +++ b/compat/variance.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include +#include + +// 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 + +// 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; + std::uintptr_t cnt; + +public: + using size_type = std::uintptr_t; + + variance() : cnt(0) {} + + void clear() { *this = variance(); } + + size_type count() { return cnt; } + + 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()); } +}; diff --git a/tracker-hatire/thread.hpp b/tracker-hatire/thread.hpp index 38b5c5dd..962b902b 100644 --- a/tracker-hatire/thread.hpp +++ b/tracker-hatire/thread.hpp @@ -10,7 +10,7 @@ #include #include -#include "api/variance.hpp" +#include "compat/variance.hpp" #include "compat/timer.hpp" enum results -- cgit v1.2.3