Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91111123
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
Fri, Nov 8, 00:41
Size
927 B
Mime Type
text/x-c++
Expires
Sun, Nov 10, 00:41 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22198651
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
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
;
}
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