October 2018
Intermediate to advanced
472 pages
10h 57m
English
Now, let's test how our trained DQN model performs on new games. The following test function uses the trained DQN model to play ten games and see whether our average target of 200 points will be achieved:
def test(env, model, states, episodes=100, render=False): """Test the performance of the DQN agent.""" scores_test = [] for episode in range(1, (episodes+1)): state = env.reset() state = state.reshape(1, states) done = False time_step = 0 while not done: if render: env.render() action = np.argmax(model.predict(state)[0]) new_state, reward, done, info = env.step(action) new_state = new_state.reshape(1, states) state = new_state time_step += 1 scores_test.append(time_step) if episode % 10 == 0: print('episode {}, score ...Read now
Unlock full access