Skip to content

Commit

Permalink
Merge pull request rail-berkeley#1 from rpinsler/fix_dqn
Browse files Browse the repository at this point in the history
Fixes DQN.
  • Loading branch information
vitchyr authored May 2, 2018
2 parents 8c2ee5d + f041fc7 commit e9ea00a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 10 additions & 0 deletions rlkit/data_management/env_replay_buffer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
from rlkit.data_management.simple_replay_buffer import SimpleReplayBuffer
from gym.spaces import Box, Discrete, Tuple

Expand All @@ -21,6 +22,15 @@ def __init__(
action_dim=get_dim(self._action_space),
)

def add_sample(self, observation, action, reward, terminal,
next_observation, **kwargs):

if isinstance(self._action_space, Discrete):
action = np.eye(self._action_space.n)[action]
super(EnvReplayBuffer, self).add_sample(
observation, action, reward, terminal,
next_observation, **kwargs)


def get_dim(space):
if isinstance(space, Box):
Expand Down
4 changes: 0 additions & 4 deletions rlkit/exploration_strategies/epsilon_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def __init__(self, action_space, prob_random_action=0.1):
self.prob_random_action = prob_random_action
self.action_space = action_space

def get_action(self, t, observation, policy, **kwargs):
action, agent_info = policy.get_action(observation)
return self.get_action_from_raw_action(action, **kwargs), agent_info

def get_action_from_raw_action(self, action, **kwargs):
if random.random() <= self.prob_random_action:
return self.action_space.sample()
Expand Down

0 comments on commit e9ea00a

Please sign in to comment.