May 2018
Intermediate to advanced
576 pages
14h 42m
English
Let's repeat the previous experiment with the Q-learning algorithm. As all of the constants are the same (as well as the choice of a ε-greedy policy and the starting point set to (0, 0)), we can directly define the function that implements the training for a single episode:
import numpy as npdef q_step(epsilon): e = 0 i = x_start j = y_start while e < max_steps: e += 1 action = select_action(epsilon, i, j) if action == 0: if i == 0: x = 0 else: x = i - 1 y = j elif action == 1: if j == width - 1: y = width - 1 else: y = j + 1 x = i elif action == 2: if i == height - 1: x = height - 1 else: x = i + 1 y = j else: if j == 0: y = 0 else: y = j - 1 x = i reward = tunnel_rewards[x, y] if is_final(x, ...
Read now
Unlock full access