diff --git a/include/am_utils/am_onlinestatistics.h b/include/am_utils/am_onlinestatistics.h index 40c6aa5..b4459f6 100644 --- a/include/am_utils/am_onlinestatistics.h +++ b/include/am_utils/am_onlinestatistics.h @@ -13,7 +13,7 @@ namespace am { class OnlineStatistics { public: OnlineStatistics() : OnlineStatistics(0) {}; - OnlineStatistics(size_t N) : ary_(0), cb(N) {}; + OnlineStatistics(size_t N) : ary_(0), cb_(N) {}; void addData( double val ); void setSize( size_t N ); void insertion_sort(std::vector& ary); @@ -29,11 +29,11 @@ class OnlineStatistics { private: size_t N; - boost::circular_buffer cb; + std::vector ary_; + boost::circular_buffer cb_; double mean_; // mean, median double m2n_; // sum of squares of differences from current mean double var_, skew_, kurt_; // variance, skewness, and kurtosis - std::vector ary_; }; diff --git a/src/am_onlinestatistics.cpp b/src/am_onlinestatistics.cpp index 0daf3d4..71fc47d 100644 --- a/src/am_onlinestatistics.cpp +++ b/src/am_onlinestatistics.cpp @@ -16,20 +16,20 @@ namespace am { * */ void OnlineStatistics::addData( double val ) { - if ( cb.size() == 0 ) { + if ( cb_.size() == 0 ) { mean_ = val; var_ = NAN; m2n_ = 0.0; - } else if ( 1 + cb.size() > cb.capacity() ) { - double tmp = cb.back(); + } else if ( 1 + cb_.size() > cb_.capacity() ) { + double tmp = cb_.back(); // std::cout << *this << std::endl; double oldmean = mean_; - mean_ = mean_ + (val - tmp)/cb.size(); + mean_ = mean_ + (val - tmp)/cb_.size(); double delta = mean_ - oldmean; double alpha = val - tmp; /* Fix this part here */ - m2n_ = m2n_ + (delta*delta*cb.size()) + alpha*(alpha+2*tmp-2*mean_ ); - var_ = m2n_ / cb.size(); + m2n_ = m2n_ + (delta*delta*cb_.size()) + alpha*(alpha+2*tmp-2*mean_ ); + var_ = m2n_ / cb_.size(); auto const ip = std::find( ary_.begin(), ary_.end(), tmp ); if ( ip != ary_.end() ) { ary_.erase(ip); @@ -37,13 +37,13 @@ void OnlineStatistics::addData( double val ) { } else { double oldmean_ = mean_; - mean_ = (val - mean_)/(cb.size()+1) + mean_; + mean_ = (val - mean_)/(cb_.size()+1) + mean_; m2n_ = m2n_ + ( val - oldmean_)*(val - mean_ ); - var_ = m2n_ / (cb.size()+1); + var_ = m2n_ / (cb_.size()+1); } ary_.insert(ary_.begin(),val ); insertion_sort(ary_); - cb.push_front(val); + cb_.push_front(val); // std::cout << *this << std::endl; } @@ -59,14 +59,14 @@ void OnlineStatistics::insertion_sort(std::vector& ary) { void OnlineStatistics::setSize( size_t N ) { - cb.set_capacity(N); - cb.erase(cb.begin(),cb.end()); + cb_.set_capacity(N); + cb_.erase(cb_.begin(),cb_.end()); ary_.clear(); } void OnlineStatistics::setDelayStats( am_utils::DelayStats &msg ) { - msg.count = cb.size(); + msg.count = cb_.size(); msg.mean_delay = getMean(); msg.stddev_delay = sqrt(getVariance()); msg.min_delay = getMin(); @@ -77,8 +77,8 @@ void OnlineStatistics::setDelayStats( am_utils::DelayStats &msg ) std::ostream& operator<<(std::ostream& os, OnlineStatistics &stats) { // os << stats.cb; os << "[ "; - for ( auto it = stats.cb.begin() ; it != stats.cb.end(); ++it ) { - os << *it << ( it + 1 == stats.cb.end() ? "" : ", " ); + for ( auto it = stats.cb_.begin() ; it != stats.cb_.end(); ++it ) { + os << *it << ( it + 1 == stats.cb_.end() ? "" : ", " ); } os << "]"; return os;