2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief StatisticAccumulator non-inline template implementation */
22 ///////////////////////////////ct.p////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////
25 // senf::StatisticAccumulator<T>
28 prefix_ senf::StatisticAccumulator<T>::StatisticAccumulator(T const & value)
29 : sum_(0), sum_squared_(0), min_( std::numeric_limits<T>::max()), max_( std::numeric_limits<T>::lowest()), cnt_(0)
35 prefix_ senf::StatisticAccumulator<T>::StatisticAccumulator()
36 : sum_(0), sum_squared_(0), min_( std::numeric_limits<T>::max()), max_( std::numeric_limits<T>::lowest()), cnt_(0)
40 prefix_ senf::StatisticAccumulator<T>::StatisticAccumulator(T const & sum, T const & sumSquared, T const & min, T const & max, unsigned count)
41 : sum_(sum), sum_squared_(sumSquared), min_(min), max_(max), cnt_(count)
45 prefix_ senf::StatisticAccumulator<T>::StatisticAccumulator(senf::StatisticsData const & data)
46 : sum_(T(data.avg) * data.cnt), sum_squared_(T(data.avg * data.avg) * data.cnt), min_(T(data.min)), max_(T(data.max)), cnt_(data.cnt)
51 prefix_ float senf::StatisticAccumulator<T>::stddev()
59 // std::max avoid rounding errors, that might cause a sqrt(<0)
60 return sqrtf(std::max(0.0f, (float(sum_squared_) / float( cnt_) - (_avg * _avg) )));
64 prefix_ void senf::StatisticAccumulator<T>::clear()
69 min_ = std::numeric_limits<T>::max();
70 max_ = std::numeric_limits<T>::lowest();
74 prefix_ void senf::StatisticAccumulator<T>::data(StatisticsData & data_)
78 data_.min = data_.avg = data_.max = NAN;
82 data_.min = (float) min_;
84 data_.max = (float) max_;
85 data_.stddev = stddev();
91 prefix_ senf::StatisticsData senf::StatisticAccumulator<T>::data()
100 prefix_ senf::StatisticAccumulator<T> senf::StatisticAccumulator<T>::operator+=(senf::StatisticAccumulator<T> const & other)
102 if (other.cnt_ > 0) {
104 this->sum_ = other.sum_;
105 this->sum_squared_ = other.sum_squared_;
106 this->cnt_ = other.cnt_;
107 this->min_ = other.min_;
108 this->max_ = other.max_;
110 this->sum_ += other.sum_;
111 this->sum_squared_ += other.sum_squared_;
112 this->cnt_ += other.cnt_;
113 this->min_ = std::min(min_,other.min_);
114 this->max_ = std::max(max_,other.max_);
121 prefix_ senf::StatisticAccumulator<T> senf::StatisticAccumulator<T>::operator*=(const float & scale)
125 this->sum_squared_ *= scale * scale;
138 prefix_ senf::StatisticsEWMA<T>::StatisticsEWMA(float alpha, T const & value)
146 prefix_ void senf::StatisticsEWMA<T>::clear(T const & value)
153 ///////////////////////////////ct.e////////////////////////////////////////