Last active
February 19, 2019 18:32
-
-
Save TomLin/24d693dfb4d88370bfd6c286702e6e9f to your computer and use it in GitHub Desktop.
Action exploration in D4PG agent.
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
# Excerpt of D4PG agent object (excerpted). | |
class AgentD4PG(): | |
""" | |
Agent implementing noisy agent | |
""" | |
def act(self, states, mode): | |
states_v = torch.Tensor(np.array(states, dtype=np.float32)).to(self.device) | |
self.actor_local.eval() | |
with torch.no_grad(): | |
mu_v = self.actor_local(states_v) | |
actions = mu_v.data.cpu().numpy() | |
self.actor_local.train() | |
if mode == "test": | |
return np.clip(actions, -1, 1) | |
elif mode == "train": | |
actions += self.epsilon * np.random.normal(size=actions.shape) # use simple normal random noise instead of OU noise | |
actions = np.clip(actions, -1, 1) | |
return actions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment