问题

使用强化学习算法探索解决方案的过程中,画出的loss/reward函数的波动很大,虽然是收敛的,但是呈现的效果不美观。

plt.figure()
xdata = list(range(len(d)))
plt.plot(time=xdata, data=d, color=color[idx], condition=labels[idx])
plt.xlabel("episode")
plt.ylabel("reward")

在这里插入图片描述
其中d是二维的列表,行数表示环境测试的次数,每行表示一组强化学习网络训练的奖励值收敛情况

解决方案

利用pandas,对该组数据进行平滑,rolling_intv是与邻近数值求平均值的个数。直观上该值越大越平滑

rolling_intv = 5
df = pd.DataFrame(d)
d = list(np.hstack(df.rolling(rolling_intv, min_periods=1).mean().values))
plt.figure()
xdata = list(range(len(d)))
plt.plot(time=xdata, data=d, color=color[idx], condition=labels[idx])
plt.xlabel("episode")
plt.ylabel("reward")

在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐