import tensorflow as tf

net = InputLayer(inputs, name='observation')
net = DenseLayer(net, n_units=4, act=tf.identity,
    W_init=tf.random_uniform_initializer(0, 0.01), b_init=None, name='q_a_s')
y = net.outputs             # action-value / rewards of 4 actions
predict = tf.argmax(y, 1)   # chose action greedily with reward. in Q-Learning, policy is greedy, so we use "max" to select the next action.

## Below we obtain the loss by taking the sum of squares difference between the target and prediction Q values.
nextQ = tf.placeholder(shape=[1, 4], dtype=tf.float32)
loss = tl.cost.mean_squared_error(nextQ, y, is_mean=False) # tf.reduce_sum(tf.square(nextQ - y))
train_op = tf.train.GradientDescentOptimizer(learning_rate=0.1).minimize(loss)

## Set learning parameters
lambd = .99    # decay factor
e = 0.1        # e-Greedy Exploration, the larger the more random
num_episodes = 10000
with tf.Session() as sess:
    tl.layers.initialize_global_variables(sess)
    for i in range(num_episodes):
