用经验回放计算dqn中的Q值
Calculating Q value in dqn with experience replay
考虑深度 Q 学习算法
1 initialize replay memory D
2 initialize action-value function Q with random weights
3 observe initial state s
4 repeat
5 select an action a
6 with probability ε select a random action
7 otherwise select a = argmaxa’Q(s,a’)
8 carry out action a
9 observe reward r and new state s’
10 store experience <s, a, r, s’> in replay memory D
11
12 sample random transitions <ss, aa, rr, ss’> from replay memory D
13 calculate target for each minibatch transition
14 if ss’ is terminal state then tt = rr
15 otherwise tt = rr + γmaxa’Q(ss’, aa’)
16 train the Q network using (tt - Q(ss, aa))^2 as loss
17
18 s = s'
19 until terminated
在第 16 步中,Q(ss, aa) 的值用于计算损失。这个Q值是什么时候计算出来的?在采取行动时还是在训练期间?
由于回放内存仅存储 < s,a,r,s' > 而不是 q 值,假设 q 值将在训练期间计算是否安全?
是的,在第 16 步中,在训练网络时,您正在使用损失函数 (tt - Q(ss, aa))^2
,因为您想要更新网络权重以逼近最近的 Q 值,计算为 rr + γmaxa’Q(ss’, aa’)
并用作目标。因此,Q(ss, aa)
是当前估计,通常在训练期间计算。
Here 您可以找到一个 Jupyter Notebook,其中包含简单的深度 Q 学习实现,这可能会有帮助。
考虑深度 Q 学习算法
1 initialize replay memory D
2 initialize action-value function Q with random weights
3 observe initial state s
4 repeat
5 select an action a
6 with probability ε select a random action
7 otherwise select a = argmaxa’Q(s,a’)
8 carry out action a
9 observe reward r and new state s’
10 store experience <s, a, r, s’> in replay memory D
11
12 sample random transitions <ss, aa, rr, ss’> from replay memory D
13 calculate target for each minibatch transition
14 if ss’ is terminal state then tt = rr
15 otherwise tt = rr + γmaxa’Q(ss’, aa’)
16 train the Q network using (tt - Q(ss, aa))^2 as loss
17
18 s = s'
19 until terminated
在第 16 步中,Q(ss, aa) 的值用于计算损失。这个Q值是什么时候计算出来的?在采取行动时还是在训练期间?
由于回放内存仅存储 < s,a,r,s' > 而不是 q 值,假设 q 值将在训练期间计算是否安全?
是的,在第 16 步中,在训练网络时,您正在使用损失函数 (tt - Q(ss, aa))^2
,因为您想要更新网络权重以逼近最近的 Q 值,计算为 rr + γmaxa’Q(ss’, aa’)
并用作目标。因此,Q(ss, aa)
是当前估计,通常在训练期间计算。
Here 您可以找到一个 Jupyter Notebook,其中包含简单的深度 Q 学习实现,这可能会有帮助。