Runs a test_episodes_per_epoch episodes and prints the result
(game, agent)
| 78 | |
| 79 | |
| 80 | def test(game, agent): |
| 81 | """Runs a test_episodes_per_epoch episodes and prints the result""" |
| 82 | print("\nTesting...") |
| 83 | test_scores = [] |
| 84 | for test_episode in trange(test_episodes_per_epoch, leave=False): |
| 85 | game.new_episode() |
| 86 | while not game.is_episode_finished(): |
| 87 | state = preprocess(game.get_state().screen_buffer) |
| 88 | best_action_index = agent.get_action(state) |
| 89 | |
| 90 | game.make_action(actions[best_action_index], frame_repeat) |
| 91 | r = game.get_total_reward() |
| 92 | test_scores.append(r) |
| 93 | |
| 94 | test_scores = np.array(test_scores) |
| 95 | print( |
| 96 | "Results: mean: {:.1f} +/- {:.1f},".format( |
| 97 | test_scores.mean(), test_scores.std() |
| 98 | ), |
| 99 | "min: %.1f" % test_scores.min(), |
| 100 | "max: %.1f" % test_scores.max(), |
| 101 | ) |
| 102 | |
| 103 | |
| 104 | def run(game, agent, actions, num_epochs, frame_repeat, steps_per_epoch=2000): |
no test coverage detected