最近在看《python深度学习》,其中3.6提到了用指数移动平均值来得到光滑的曲线:
def smooth_curve(points, factor=0.9):
smoothed_points = []
for point in points:
if smoothed_points:
previous = smoothed_points[-1]
smoothed_points.append(previous * factor + point * (1 - factor))
else:
smoothed_points.append(point)
return smoothed_points
smooth_mae_history = smooth_curve(average_mae_history[10:])
plt.plot(range(1, len(smooth_mae_history) + 1), smooth_mae_history)
plt.xlabel('Epochs')
plt.ylabel('Validation MAE')
plt.show()
百度了一下,指数移动平均值的计算公式应该是:
EMAtoday=α * Pricetoday + ( 1 - α ) * EMAyesterday;
如果按照这个公式,计算代码应为:
factor * point + (1 - factor) * previous
而非书中提到的:
previous * factor + point * (1 - factor)
想请教下,是书上错了还是我理解错了?还想请教下factor=0.9时怎么得出的?