October 2018
Intermediate to advanced
472 pages
10h 57m
English
This module contains the test() function, which will be called in the train_dqn.py script to test the performance of the DQN agent:
"""This module contains function to test the performance of the DQN model."""import numpy as npdef 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: ...
Read now
Unlock full access