(state)
| 76 | |
| 77 | |
| 78 | def 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 | |
| 95 | def finish_episode(): |