October 2018
Intermediate to advanced
472 pages
10h 57m
English
In this module, we include the memory() and train() functions and also the calls to train and test the reinforcement learning model:
"""This module is used to train and test the DQN agent."""import randomimport numpy as npfrom agent_replay_dqn import agent, agent_action, replay, performance_plotfrom hyperparameters_dqn import *from test_dqn import testfrom keras import backend as kfrom collections import dequeimport gymenv = gym.make('CartPole-v1')# Set seed for reproducibilityseed_val = 456np.random.seed(seed_val)env.seed(seed_val)random.seed(seed_val)states = env.observation_space.shape[0]actions = env.action_space.ntraining_data = deque(maxlen=deque_len)def memory(state, new_state, reward, done, action): """Function ...Read now
Unlock full access