Code
Code
A finite version of the problem
The action set keeps five commands. Each one turns at a fixed rate, and the sharper turns drive more slowly:
The state keeps two pieces of the 28 numbers, each cut into a few bins:
- The goal bearing falls into one of 8 sectors of 45 degrees, centered on straight ahead, left, behind, right and the four diagonals.
- The lidar is reduced to three sectors: front ( degrees), left and right (45 to 135 degrees to each side). Each sector reports its shortest range as near (under 0.45 m), middle (0.45 to 0.9 m) or far.
Code
Code
The Q-learning update
Q-learning keeps a table and moves one entry after every step toward a target built from the reward and the best action value in the next state: This is the update of TD prediction written for action values. The term in brackets is the TD error, the gap between the TD target and the current estimate. The update moves a fraction of the way across that gap. The Monte Carlo estimate of the navigation MDP section did something else: it waited until an episode ended and averaged the actual returns . TD bootstraps instead. It updates after every 0.2 s step, using the table’s own estimate of the next state in place of the rest of the return. An episode here lasts up to 200 steps, so TD makes up to 200 updates in the time Monte Carlo waits for one return. The comparison of TD and Monte Carlo shows the trade: the TD target has lower variance, and it is biased while the table is still wrong. Compare the target with the value-iteration backup of the navigation MDP section, written for action values: Value iteration takes the expected reward and the sum over next states from the model. Q-learning replaces both with the one reward and the one next state that the robot actually experienced. One sample is a noisy estimate of the expectation. The step size averages many of them, so over repeated visits moves toward the mean of the targets, which is the backup applied to the current table. That is why Q-learning needs no model: the robot’s own transitions are samples from . After a goal or a collision the next state has no future, so the target is alone. After a timeout the robot still has a future, so the update bootstraps as usual. The agent explores with an -greedy policy: with probability it picks a random action, and otherwise the action with the largest . Here falls linearly from 1 to 0.05 over the first 60% of training, and . The update uses the greedy action in the target while the robot follows the -greedy one, which makes Q-learning off-policy. SARSA would use the action the robot actually takes next: SARSA learns the value of the -greedy policy itself. That value includes the random actions, some of which turn the robot into an obstacle. Q-learning learns the value of the greedy policy, whatever the exploration does. The Q-learning section shows the consequence on the cliff-walking gridworld: SARSA learns a safer path that stays away from the cliff, and Q-learning learns the shortest one. In a finite MDP, the table converges to if every state-action pair keeps being visited and the step size shrinks over time. Neither holds exactly here: stays at 0.1, and the end of this section shows that the discrete state is not quite Markov. The floor of 0.05 keeps every action in use.Code
Code
Code
Code
Where the table falls short
Two things limit the tabular agent: how often it sees each state, and how much the state hides.Found an error on this page? Report an issue.

