Coding the file

We will now code the file:

  1. Import packages: First, we will import the required packages as follows:
import numpy as npimport gymimport sys
  1. Set the neural network initializers: Then, we will set the neural network parameters (we will use two hidden layers) and the initializers for the weights and biases. As we have also done in past chapters, we will use the Xavier initializer for the weights and a small positive value for the initial values of the biases:
nhidden1 = 64 nhidden2 = 64 xavier = tf.contrib.layers.xavier_initializer()bias_const = tf.constant_initializer(0.05)rand_unif = tf.keras.initializers.RandomUniform(minval=-3e-3,maxval=3e-3)regularizer = tf.contrib.layers.l2_regularizer(scale=0.0 ...

Get TensorFlow Reinforcement Learning Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.