Deep Reinforcement Learning with Double Q-learning
論文地址:
筆記
在傳統強化學習領域里面,學者們已經認識到了Q-learning 存在overestimate的問題。overestimation 會損害performance,因為overestimate很可能是不均勻的.造成overestimation的原因多種多樣,根本原因還是我們不知道action value的真實值、
DQN的參數更新公式
從公式上看\(Y_t^{DQN} = R_{t+1} + \gamma\underset{a}{max} Q(S_{t+1},a;\theta_t^{-})\).
我們既用了estimator \(Q\)找到能讓value 最大的action \(a\),並且繼續使用這個estimator \(Q\)估計這個action value。有種權利不受約束,自己監管自己的感覺。
更好的方式是一個estimator找到具有最優value 的\(a\),另一個estimator去估計這個\(a\)對應的value。這就是action selection 和action evaluation
傳統的 double Q-learning 提出的解決方式很簡單就是使用了兩個estimator 隨機交替更新。
我們可以把double Q-learning 的公式寫作下面的公式,\(\theta,\theta'\)分別對應兩個estimator 的參數.我們交替更新\(\theta,\theta'\)
在DQN 中我們天然的就有兩個estimator 一個是target policy 對應estimator,參數是\(\theta^{-}\),一個是 behavior policy 對應的estimator,參數是\(\theta\)。(不需要交替更新)
代碼
def compute_td_loss(batch_size):
state, action, reward, next_state, done = replay_buffer.sample(batch_size)
state = Variable(torch.FloatTensor(np.float32(state)))
next_state = Variable(torch.FloatTensor(np.float32(next_state)))
action = Variable(torch.LongTensor(action))
reward = Variable(torch.FloatTensor(reward))
done = Variable(torch.FloatTensor(done))
q_values = current_model(state)
next_q_values = current_model(next_state)
next_q_state_values = target_model(next_state)
q_value = q_values.gather(1, action.unsqueeze(1)).squeeze(1)
next_q_value = next_q_state_values.gather(1, torch.max(next_q_values, 1)[1].unsqueeze(1)).squeeze(1)
expected_q_value = reward + gamma * next_q_value * (1 - done) # target
loss = (q_value - Variable(expected_q_value.data)).pow(2).mean()
optimizer.zero_grad()
loss.backward()
optimizer.step()
return loss