I presume it is some kind of moving average, but the valid range is between 0 and 1.
Asked
Active
Viewed 1.8k times
2 Answers
82
It is called exponential moving average, below is a code explanation how it is created.
Assuming all the real scalar values are in a list called scalars the smoothing is applied as follows:
def smooth(scalars: List[float], weight: float) -> List[float]: # Weight between 0 and 1
last = scalars[0] # First value in the plot (first timestep)
smoothed = list()
for point in scalars:
smoothed_val = last * weight + (1 - weight) * point # Calculate smoothed value
smoothed.append(smoothed_val) # Save it
last = smoothed_val # Anchor the last smoothed value
return smoothed
bluesummers
- 9,008
- 6
- 64
- 95
-
2I wish you could pick between that and a sliding moving average! – Avedis Dec 21 '20 at 16:11
-
This was really helpful! Thanks. – Abhik Banerjee Jan 13 '21 at 12:08
4
Here is the actual piece of source code that performs that exponential smoothing the with some additional de-biasing explained in the comments to compensate for the choice of the zero initial value:
last = last * smoothingWeight + (1 - smoothingWeight) * nextVal
Ben Usman
- 7,179
- 5
- 42
- 64