Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Ewma Class Reference

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.
 

Detailed Description

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.

Definition at line 56 of file Ewma.hxx.

Constructor & Destructor Documentation

◆ Ewma()

Ewma::Ewma ( float  alpha = 0.8)
inline

Constructor.

Parameters
alphacoefficient of the EWMA computation. The lower the value is the faster the average converges to current speed. The higher this value is the more the averaging will smoothe the speed values read out.

Definition at line 63 of file Ewma.hxx.

Member Function Documentation

◆ add_absolute()

void Ewma::add_absolute ( uint32_t  offset)
inline

Sets the absolute value where the transfer is.

Sequential calls must have an increasing value of ‘offset’.

Parameters
offsettells where the transfer is currently.

Definition at line 71 of file Ewma.hxx.

◆ add_diff()

void Ewma::add_diff ( uint32_t  bytes)
inline

Notifies the average algorithm that since the last call ‘bytes’ additional bytes were transferred.

Parameters
bytestell the additional number of bytes that arrived since the last call.

Definition at line 80 of file Ewma.hxx.

◆ avg()

float Ewma::avg ( )
inline
Returns
the current average speed in bytes/sec.

Definition at line 99 of file Ewma.hxx.

◆ current_time()

long long Ewma::current_time ( )
inlineprivate

Helper function to get the current time.

Returns
current time.

Definition at line 106 of file Ewma.hxx.

Member Data Documentation

◆ alpha_

float Ewma::alpha_
private

coefficient for EWMA

Definition at line 120 of file Ewma.hxx.

◆ avg_

float Ewma::avg_ {0.0}
private

current state of EWMA

Definition at line 121 of file Ewma.hxx.

◆ lastMeasurementTimeNsec_

long long Ewma::lastMeasurementTimeNsec_ {0}
private

When did we take the last measurement.

Definition at line 123 of file Ewma.hxx.

◆ lastOffset_

uint32_t Ewma::lastOffset_ {0}
private

What was the progress offset at the time of the last measurement taken.

Definition at line 125 of file Ewma.hxx.


The documentation for this class was generated from the following file: