MCPcopy Create free account
hub / github.com/pytorch/examples / select_action

Function select_action

reinforcement_learning/actor_critic.py:78–92  ·  view source on GitHub ↗
(state)

Source from the content-addressed store, hash-verified

76
77
78def select_action(state):
79 state = torch.from_numpy(state).float()
80 probs, state_value = model(state)
81
82 # create a categorical distribution over the list of probabilities of actions
83 m = Categorical(probs)
84
85 # and sample an action using the distribution
86 action = m.sample()
87
88 # save to action buffer
89 model.saved_actions.append(SavedAction(m.log_prob(action), state_value))
90
91 # the action to take (left or right)
92 return action.item()
93
94
95def finish_episode():

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected