(state)
| 299 | |
| 300 | |
| 301 | def select_action(state): |
| 302 | global steps_done |
| 303 | sample = random.random() |
| 304 | eps_threshold = EPS_END + (EPS_START - EPS_END) * \ |
| 305 | math.exp(-1. * steps_done / EPS_DECAY) |
| 306 | steps_done += 1 |
| 307 | if sample > eps_threshold: |
| 308 | with torch.no_grad(): |
| 309 | # t.max(1) will return the largest column value of each row. |
| 310 | # second column on max result is index of where max element was |
| 311 | # found, so we pick action with the larger expected reward. |
| 312 | return policy_net(state).max(1).indices.view(1, 1) |
| 313 | else: |
| 314 | return torch.tensor([[env.action_space.sample()]], device=device, dtype=torch.long) |
| 315 | |
| 316 | |
| 317 | episode_durations = [] |
no test coverage detected