Skip to content

Instantly share code, notes, and snippets.

@zzxx-husky
Created August 1, 2017 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzxx-husky/cd89860657327a23c33bac24026d5ddc to your computer and use it in GitHub Desktop.
Save zzxx-husky/cd89860657327a23c33bac24026d5ddc to your computer and use it in GitHub Desktop.
DQN
class DQN(DQNBase):
def __init__(self):
self.k = HP['frame_skipping']
def initialState(self):
states = []
obs = self.env.reset()
obs = self.model.preprocess(obs)
for _ in range(HP['stacked_frame_size']):
states.append(obs)
return np.dstack(tuple(states))
def executeAction(self, action, state):
if self.k == HP['frame_skipping']:
# new action
self.k = 0
self.last_action = action
else:
# repeat last action
self.k += 1
action = self.last_action
s1, reward, done, _ = self.env.step(action)
newObservation = self.model.preprocess(s1)
newState = state[:, :, 1:]
newState = np.dstack((newState, newObservation))
return {'state': state,
'action': action,
'reward': reward,
'next_state': newState,
'done': done }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment