MCPcopy Index your code
hub / github.com/pytorch/tutorials / select_action

Function select_action

intermediate_source/reinforcement_q_learning.py:301–314  ·  view source on GitHub ↗
(state)

Source from the content-addressed store, hash-verified

299
300
301def 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
317episode_durations = []

Callers 1

Calls 1

sampleMethod · 0.80

Tested by

no test coverage detected