|
Click
|
An exponentially weighted moving average. More...
#include <click/ewma.hh>
Inherits P.
Public Types | |
| typedef P::value_type | value_type |
Public Member Functions | |
| DirectEWMAX () | |
| Construct a EWMA with initial average 0. | |
| DirectEWMAX (value_type scaled_value) | |
| Construct a EWMA with initial scaled average scaled_value. | |
| value_type | scaled_average () const |
| Return the current scaled moving average. | |
| value_type | unscaled_average () const |
| Return the current moving average, rounded up. | |
| void | clear () |
| Reset the EWMA to value 0. | |
| void | assign (value_type scaled_value) |
| Assign the EWMA to scaled average scaled_value. | |
| void | update (value_type x) |
| Update the moving average with a new observation. | |
| void | update_n (value_type x, unsigned n) |
| Update the moving average with n identical observations. | |
| String | unparse () const |
| Unparse the current average into a String. | |
| void | update_with (value_type x) |
| Update the moving average with a new observation (deprecated). | |
An exponentially weighted moving average.
The DirectEWMAX template class represents a simple exponentially weighted moving average. The average starts out with value 0. The update() function adds a new observation to the average.
The template parameter P defines three EWMA parameters: value type, stability shift, and scale factor.
The value type is simply the unsigned integral type used to store the average. It is also the type of each observation. unsigned and uint64_t are examples.
The stability shift specifies alpha, the stability parameter. Concretely, alpha = 1. / (2 ** stability_shift). Thus, a stability shift of 4 corresponds to an alpha of 1/16.
The scaling factor specifies how many bits of fraction are kept per observation. Fraction bits are necessary to account for small differences between observations. For example, consider a EWMA with value 0, alpha 1/16, and 0 bits of fraction. Assume the EWMA begins to observe a stream of observations equal to 1. Despite these observations, the EWMA's value will never change from 0, since the 1/16 alpha factor rounds the new observations down to 0. At least 4 bits of fraction are required to account for this difference. There is a tradeoff: the more bits of fraction, the more precise the EWMA, but the less bits available to account for large values.
These EWMA parameters are defined by five of P's members, two typedefs and three possibly static member functions.
The EWMA's value type. Example: unsigned.
The signed version of P::value_type. Used internally. Example: int.
This function should return this EWMA's stability shift (see above).
This function should return this EWMA's scaling factor (see above).
Since DirectEWMAX inherits from an object of type P, these members are also directly available to callers.
The FixedEWMAXParameters and StabilityEWMAXParameters types are good template arguments for DirectEWMAX.
|
inline |
Construct a EWMA with initial average 0.
|
inline |
Construct a EWMA with initial scaled average scaled_value.
|
inline |
Return the current scaled moving average.
|
inline |
Return the current moving average, rounded up.
|
inline |
Reset the EWMA to value 0.
|
inline |
Assign the EWMA to scaled average scaled_value.
|
inline |
Update the moving average with a new observation.
| x | the observation (unscaled) |
| void DirectEWMAX< P >::update_n | ( | value_type | x, |
| unsigned | n | ||
| ) |
Update the moving average with n identical observations.
| x | the observation (unscaled) |
| n | number of observations |
|
inline |
Unparse the current average into a String.
|
inline |
Update the moving average with a new observation (deprecated).
| x | the observation (unscaled) |