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 inline template implementation */
19 #define prefix_ inline
20 ///////////////////////////////cti.p///////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////
23 // senf::StatisticAccumulator<T>
26 prefix_ T senf::StatisticAccumulator<T>::min()
33 prefix_ T senf::StatisticAccumulator<T>::max()
40 prefix_ T senf::StatisticAccumulator<T>::sum()
47 prefix_ T senf::StatisticAccumulator<T>::sum2()
54 prefix_ float senf::StatisticAccumulator<T>::avg()
57 return cnt_ == 0 ? NAN : float(sum_) / float(cnt_);
61 prefix_ float senf::StatisticAccumulator<T>::rms()
64 return cnt_ == 0 ? NAN : sqrtf(float(sum_squared_) / float(cnt_));
68 prefix_ unsigned senf::StatisticAccumulator<T>::count()
75 prefix_ void senf::StatisticAccumulator<T>::accumulate(T const & value)
78 sum_squared_ += value * value;
80 min_ = std::min(min_, value);
81 max_ = std::max(max_, value);
85 prefix_ senf::StatisticAccumulator<T>::operator bool()
96 prefix_ void senf::StatisticsEWMA<T>::accumulate(T const & value)
98 ewma_ = (ewma_ * (1.0f - alpha_)) + (value * alpha_);
103 prefix_ void senf::StatisticsEWMA<T>::accumulateWithLoss(T const & value, unsigned numLost)
105 // we substitute the lost data with a avg of the last ewma and the new data
106 T avg ((ewma_ + value) * 0.5f);
108 // account for lost data with avg
109 for (unsigned n = 0; n < numLost; n++) {
118 prefix_ senf::StatisticsEWMA<T>::operator bool()
125 prefix_ bool senf::StatisticsEWMA<T>::operator<(senf::StatisticsEWMA<T> const & other)
128 return ewma_ < other.ewma_;
132 prefix_ unsigned senf::StatisticsEWMA<T>::count()
139 prefix_ T const & senf::StatisticsEWMA<T>::ewma()
146 prefix_ float const & senf::StatisticsEWMA<T>::alpha()
153 ///////////////////////////////cti.e///////////////////////////////////////
160 // comment-column: 40
161 // c-file-style: "senf"
162 // indent-tabs-mode: nil
163 // ispell-local-dictionary: "american"
164 // compile-command: "scons -U"