Fix a bug of DQN

This commit is contained in:
Shangtong Zhang
2017-05-29 14:01:19 -06:00
parent db580795f3
commit 4908202976
5 changed files with 77 additions and 35 deletions
+4 -3
View File
@@ -11,7 +11,8 @@ def NStepQLearning(batch_states, batch_actions, batch_rewards,
reward = 0
else:
with agent.network_lock:
reward = np.max(agent.target_network.predict(tailing_state))
reward = np.max(agent.target_network.predict(
np.reshape(tailing_state, (1, ) + tailing_state.shape)))
rewards = []
for r in reversed(batch_rewards):
reward = r + agent.discount * reward
@@ -22,7 +23,7 @@ def OneStepQLearning(batch_states, batch_actions, batch_rewards,
tailing_state, tailing_action, terminal, agent):
batch_states.append(tailing_state)
with agent.network_lock:
q_next = agent.target_network.predict(np.vstack(batch_states[1:]))
q_next = agent.target_network.predict(np.asarray(batch_states[1:]))
q_next = np.max(q_next, axis=1)
if terminal:
q_next[-1] = 0
@@ -35,7 +36,7 @@ def OneStepSarsa(batch_states, batch_actions, batch_rewards,
batch_states.append(tailing_state)
batch_actions.append(tailing_action)
with agent.network_lock:
q_next = agent.target_network.predict(np.vstack(batch_states[1:]))
q_next = agent.target_network.predict(np.asarray(batch_states[1:]))
q_next = q_next[np.arange(len(batch_actions[1:])), batch_actions[1:]]
if terminal:
q_next[-1] = 0