|
Open Model Railroad Network (OpenMRN)
|
Exponentially weighted moving average. More...
#include <Ewma.hxx>
Public Member Functions | |
| Ewma (float alpha=0.8) | |
| Constructor. | |
| void | add_absolute (uint32_t offset) |
| Sets the absolute value where the transfer is. | |
| void | add_diff (uint32_t bytes) |
| Notifies the average algorithm that since the last call ‘bytes’ additional bytes were transferred. | |
| float | avg () |
Private Member Functions | |
| long long | current_time () |
| Helper function to get the current time. | |
Private Attributes | |
| float | alpha_ |
| coefficient for EWMA | |
| float | avg_ {0.0} |
| current state of EWMA | |
| long long | lastMeasurementTimeNsec_ {0} |
| When did we take the last measurement. | |
| uint32_t | lastOffset_ {0} |
| What was the progress offset at the time of the last measurement taken. | |
Exponentially weighted moving average.
This class allows an O(1) representation of an average over a timeseries of data. This is the algorithm that Linux is using for the loadavg calculation. The algorithm is parametrized by a coefficient \alpha. The larger \alpha is, the longer "memory" the average has, meaning that the slower the average adapts to a changing situation.
This class is implemented to perform computation of transfer speed. It keeps track of the time since the last call, computes the speed in bytes/sec, and averages the speed values according to the EWMA algorithm.
This class currently does not work under freertos due to the clock readout mechanism used. To fix it, we'd need to create an API for an equally accurate clock readout mechanism under linux and freertos.
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
private |
|
private |