引用来自ShangtongZhang的代码chapter06/maximization_bias.py
因为TD算法中的target policy建立中经常会用到maximization操作,在这些算法中,a maximum over estimated values is used implicitly as an estimate of the maximum value,这可能会导致显著的正向偏差,本例通过一个简单的MRP来讨论这个问题。
问题描述
这个例子是为了说明并解决TD方法将估计的最大值作为实际Q的最大值造成的正向偏差(bias),使用了一个简单的MRP:
A是start state,左右的灰色小方格是terminal state。A状态下可以有两个action:left和right;如果向右直接会结束,reward=0;向左则进入B状态,B状态有多个达到左边terminal state的actions可选,并对应reward=N(-0.1,1),所以(A,left)开始的expect return = -0.1。
引入模块并定义常量
1 | # 6.7 Maximization Bias and Double Learnin |
提供choose action和take action函数
1 | # choose an action based on epsilon greedy algorithm |
使用Q-Learning 和 Double Q-Learning方法来训练并计算policy选择(A|left)的概率
1 | # if there are two state action pair value array, use double Q-Learning |
1 | # Figure 6.7, 1,000 runs may be enough, the number of actions in state B will also affect the curves |
100%|██████████| 1000/1000 [00:44<00:00, 23.10it/s]