mirror of
https://github.com/wassname/DeepRL.git
synced 2026-09-10 11:40:58 +08:00
Fix a bug of DQN
This commit is contained in:
+4
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user