Skip to content

Instantly share code, notes, and snippets.

@elumixor
Created May 24, 2020 22:32
Show Gist options
  • Select an option

  • Save elumixor/cec4d042835c969190929ca52ffddb0c to your computer and use it in GitHub Desktop.

Select an option

Save elumixor/cec4d042835c969190929ca52ffddb0c to your computer and use it in GitHub Desktop.
TRPO Get Action
from torch.distributions import Categorical
def get_action(state):
state = torch.tensor(state).float().unsqueeze(0) # Turn state into a batch with a single element
dist = Categorical(actor(state)) # Create a distribution from probabilities for actions
return dist.sample().item()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment