Created
August 1, 2017 05:47
-
-
Save zzxx-husky/cd89860657327a23c33bac24026d5ddc to your computer and use it in GitHub Desktop.
DQN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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