progressbar.algorithms module¶
Smoothing algorithms backing SmoothingETA and similar widgets.
Both concrete implementations below seed their running state with the first observed value rather than 0, so an EMA/DEMA-backed ETA doesn’t start out biased toward zero before enough samples have arrived. Both update methods also accept an elapsed argument that they currently ignore – it’s part of the SmoothingAlgorithm contract (for algorithms that might weight by time rather than call count) but neither implementation here uses it.
- class progressbar.algorithms.DoubleExponentialMovingAverage(alpha: float = 0.5)[source]¶
Bases:
SmoothingAlgorithmAn EMA of an EMA (DEMA), reducing the lag a single EMA carries.
Reacts to recent changes faster than the plain ExponentialMovingAverage.
Set the smoothing factor.
- Parameters:
alpha – Weight given to the newest observation in each of the two nested EMAs (0-1); higher tracks recent values more closely, lower smooths harder.
- class progressbar.algorithms.ExponentialMovingAverage(alpha: float = 0.5)[source]¶
Bases:
SmoothingAlgorithmExponentially weighted moving average (EMA) of the observed values.
More responsive to recent changes than a simple moving average, with less lag.
Set the smoothing factor.
- Parameters:
alpha – Weight given to the newest observation on each update() (0-1); higher tracks recent values more closely, lower smooths harder.
- update(new_value: float, elapsed: timedelta) float[source]¶
Fold new_value into the running average.
- Parameters:
new_value – Latest observed value.
elapsed – Accepted for SmoothingAlgorithm compatibility but not used by this implementation – the average is weighted by call count, not by wall-clock time.
- Returns:
The updated EMA.