moving_average¶
Exponentially weighted moving average computation.
This module provides the :class:MovingAverage class which maintains a running
average of values using an exponential smoothing factor. Each new value is
blended with the previous average according to the factor.
MovingAverage
¶
Maintain an exponentially weighted moving average of values.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
The current moving average value. |
Example
ma = moving_average.MovingAverage(0.25)
ma.update(10) # 10: the first value is taken as-is.
ma.update(20) # 17.5: 10 * 0.25 + 20 * 0.75.
Source code in py_misc_utils/moving_average.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
update(value)
¶
Incorporate a new value into the moving average.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
The new observation to blend into the average. |
required |
Returns:
| Type | Description |
|---|---|
|
The updated moving average value. |
Source code in py_misc_utils/moving_average.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |