MCPcopy Create free account
hub / github.com/rlcode/reinforcement-learning / evaluate

Function evaluate

4-atari-hard/3-robustify.py:335–368  ·  view source on GitHub ↗

From-reset, sticky-action, eps-greedy 0.0 eval — the RL-policy number.

(net, demo, device, n_episodes, n_actions, seed)

Source from the content-addressed store, hash-verified

333
334
335def evaluate(net, demo, device, n_episodes, n_actions, seed):
336 """From-reset, sticky-action, eps-greedy 0.0 eval — the RL-policy number."""
337 e = ReplayResetEnv(demo, seed=seed + 99, sticky=STICKY, noop_max=30)
338 e.starting_point = 0 # always from reset
339 e.frac_sample = 0.0
340 # Eval must honor targets montezuma_goexplore_robust.protocol.termination=game_over:
341 # turn OFF the training-curriculum kills so a from-reset episode runs to a real
342 # game_over, not a ~allowed_lag-step lag-kill window. Otherwise value_mean reports a
343 # key-but-slower-than-demo policy as ~0 and the canary's first-key/retreat signal is
344 # destroyed (preflight S1). lag-kill needs t>allowed_lag & t<n -> allowed_lag=n makes
345 # it unreachable; success-kill needs score>=total_return-deficit -> huge -deficit off.
346 e.allowed_lag = e.n
347 e.allowed_score_deficit = -1e18
348 e.max_steps = 4500 # standard Montezuma eval cap = 18000 frames / frameskip 4
349 # (atari-ale-protocol; same as RND montezuma episode_cap). Bounds
350 # a passive policy that would otherwise never reach game_over.
351 scores = []
352 for _ in range(n_episodes):
353 frame = e.reset()
354 stack = _stack_init(frame)
355 hx = torch.zeros(1, net.gru_dim, device=device)
356 ret = 0.0
357 done = False
358 while not done:
359 with torch.no_grad():
360 obs = torch.as_tensor(stack[None], dtype=torch.float32, device=device)
361 logits, _, hx = net.step(obs, hx)
362 a = int(logits.argmax(-1))
363 frame, _, done, info = e.step(a)
364 ret += info["raw_reward"]
365 stack = np.concatenate([stack[1:], frame[None]], axis=0)
366 scores.append(ret)
367 e.env.close()
368 return scores
369
370
371if __name__ == "__main__":

Callers 1

mainFunction · 0.85

Calls 6

resetMethod · 0.95
stepMethod · 0.95
ReplayResetEnvClass · 0.90
_stack_initFunction · 0.85
appendMethod · 0.80
stepMethod · 0.45

Tested by

no test coverage detected