Skip to content

Instantly share code, notes, and snippets.

@TomLin
Last active February 19, 2019 18:32
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 TomLin/24d693dfb4d88370bfd6c286702e6e9f to your computer and use it in GitHub Desktop.
Save TomLin/24d693dfb4d88370bfd6c286702e6e9f to your computer and use it in GitHub Desktop.
Action exploration in D4PG agent.
# 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