【问题标题】:Double counting in temporal difference learning时间差异学习中的双重计数
【发布时间】:2016-06-05 15:35:07
【问题描述】:

我正在研究一个时间差异学习示例 (https://www.youtube.com/watch?v=XrxgdpduWOU),我在 python 实现中遇到了以下等式的问题,因为我似乎重复计算了奖励和 Q。

如果我将下面的网格编码为二维数组,我的当前位置是 (2, 2),目标是 (2, 3),假设最大奖励是 1。让 Q(t) 是我的平均平均值当前位置,则 r(t+1) 为 1,我假设最大 Q(t+1) 也为 1,这导致我的 Q(t) 接近 2(假设 gamma 为 1)。这是正确的,还是我应该假设 Q(n),其中 n 是终点是 0?

编辑以包含代码 - 我修改了 get_max_q 函数以返回 0,如果它是终点并且值现在都低于 1(我认为这是更正确的,因为奖励只是 1)但不确定这是否是正确的方法(之前我将它设置为当它是终点时返回 1)。

#not sure if this is correct
def get_max_q(q, pos):
    #end point 
    #not sure if I should set this to 0 or 1
    if pos == (MAX_ROWS - 1, MAX_COLS - 1):
        return 0
    return max([q[pos, am] for am in available_moves(pos)])

def learn(q, old_pos, action, reward):
    new_pos = get_new_pos(old_pos, action)
    max_q_next_move = get_max_q(q, new_pos) 

    q[(old_pos, action)] = q[old_pos, action] +  alpha * (reward + max_q_next_move - q[old_pos, action]) -0.04

def move(q, curr_pos):
    moves = available_moves(curr_pos)
    if random.random() < epsilon:
        action = random.choice(moves)
    else:
        index = np.argmax([q[m] for m in moves])
        action = moves[index]

    new_pos = get_new_pos(curr_pos, action)

    #end point
    if new_pos == (MAX_ROWS - 1, MAX_COLS - 1):
        reward = 1
    else:
        reward = 0

    learn(q, curr_pos, action, reward)
    return get_new_pos(curr_pos, action)

=======================
OUTPUT
Average value (after I set Q(end point) to 0)
defaultdict(float,
            {((0, 0), 'DOWN'): 0.5999999999999996,
             ((0, 0), 'RIGHT'): 0.5999999999999996,
              ...
             ((2, 2), 'UP'): 0.7599999999999998})

Average value (after I set Q(end point) to 1)
defaultdict(float,
        {((0, 0), 'DOWN'): 1.5999999999999996,
         ((0, 0), 'RIGHT'): 1.5999999999999996,
         ....
         ((2, 2), 'LEFT'): 1.7599999999999998,
         ((2, 2), 'RIGHT'): 1.92,
         ((2, 2), 'UP'): 1.7599999999999998})

【问题讨论】:

  • 显示你的代码,显示你想要的输出,并显示你得到的不正确的输出。
  • @TomKarzes 谢谢你,我已经包含了我的代码和输出!

标签: python machine-learning reinforcement-learning temporal-difference


【解决方案1】:

Q 值表示在剧集结束前您期望获得多少奖励的估计值。因此,在最终状态下,maxQ = 0,因为在那之后您将不再获得任何奖励。因此,t 处的 Q 值为 1,这对于您的未折现问题是正确的。但是你不能忽略等式中的gamma,将其添加到你的公式中以使其打折。因此,例如,如果gamma = 0.9t 处的 Q 值为 0.9。在 (2,1) 和 (1,2) 处,它将是 0.81,依此类推。

【讨论】:

  • 谢谢,我会用伽玛值做实验!感谢您的解释,按照您解释的方式,maxQ 在终端状态下为 0 是有道理的。
猜你喜欢
  • 2012-05-28
  • 2016-05-25
  • 2014-06-07
  • 2016-03-14
  • 2013-05-21
  • 1970-01-01
  • 2011-06-18
  • 2019-06-07
  • 1970-01-01
相关资源
最近更新 更多