October 2018
Intermediate to advanced
472 pages
10h 57m
English
For SARSA learning, we have only one script, which implements both the training and testing of the SARSA agent:
"""This module implements training and testing of SARSA agent."""import gymimport numpy as npfrom keras.layers import Dense, Activation, Flattenfrom keras.models import Sequentialfrom rl.agents import SARSAAgentfrom rl.policy import EpsGreedyQPolicy# load the environmentenv = gym.make('CartPole-v1')# set seedseed_val = 456env.seed(seed_val)np.random.seed(seed_val)states = env.observation_space.shape[0]actions = env.action_space.ndef agent(states, actions): """Agent/Deep Neural Network.""" model = Sequential() model.add(Flatten(input_shape=(1, states))) model.add(Dense(16)) model.add(Activation('relu')) ...Read now
Unlock full access