blu*_*ers 29
@ drpng的答案指向了正确的解释,但由于链接可能在这里下去,因此使用的平滑函数的Pythonic转换代码.
假设所有真实标量值都在名为scalars平滑的列表中,则应用如下:
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
Run Code Online (Sandbox Code Playgroud)
这是执行指数平滑的实际源代码,并在注释中解释了一些额外的去偏置,以补偿零初始值的选择:
last = last * smoothingWeight + (1 - smoothingWeight) * nextVal
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7295 次 |
| 最近记录: |