Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92051558
moving_average.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 16, 23:00
Size
1 KB
Mime Type
text/x-c++
Expires
Mon, Nov 18, 23:00 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22368725
Attached To
rSPECMICP SpecMiCP / ReactMiCP
moving_average.hpp
View Options
#ifndef SPECMICP_UTILS_MOVINGAVERAGE_HPP
#define SPECMICP_UTILS_MOVINGAVERAGE_HPP
#include "common.hpp"
namespace specmicp {
namespace utils {
//! \brief Exponential moving average
//!
//! https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
//!
//! @param alpha coefficient between 0 and 1
//! @param init initial value of the average
class ExponentialMovingAverage
{
public:
ExponentialMovingAverage(scalar_t alpha, scalar_t init):
m_alpha(alpha),
m_current_value(init)
{
}
//! \brief Add a point in the series, return current average value
scalar_t add_point(scalar_t value){
m_current_value = m_alpha*value + (1-m_alpha)*m_current_value;
return m_current_value;
}
//! \brief Return the current average value
scalar_t current_value() {
return m_current_value;
}
//! \brief Reset the average to 'value'
void reset(scalar_t value) {
m_current_value = value;
}
private:
scalar_t m_alpha;
scalar_t m_current_value;
};
} // end namespace utils
} // end namespace specmicp
#endif // SPECMICP_UTILS_MOVINGAVERAGE_HPP
Event Timeline
Log In to Comment