The cleaning robot MDP
The state is the position of the robot, and the action moves it one cell to the left or to the right. The charger is in state 0 and the can is in state 5. Both are terminal: once the robot reaches either one, it stays there whatever it does. With deterministic moves, the next state is Reaching the can earns a reward of 5 and reaching the charger earns 1. Every other transition, including any action taken in a terminal state, earns 0: The discount factor is , so a reward one step later is worth half as much.Code
Code
q-value iteration
The optimal action-value function is the return of taking action in state and acting optimally afterwards. It satisfies the Bellman optimality equation for action values, q-value iteration turns this equation into an update. Start from and apply the right-hand side to every pair , using the previous table inside the max, to get . Stop when no entry changes by more than a small tolerance. Once is known, the optimal policy needs no model at all: in each state, pick the action with the larger . This is value iteration with the action values kept. Value Iteration stores one number per state, , and computes action values only briefly inside each backup. q-value iteration stores one number per state and action. The two produce the same sequence: with , the update above is exactly the value iteration update. Keeping costs more memory, but it removes the model from policy extraction. From you need the model again to look one step ahead, while from you only take the argmax in each state. Q-learning estimates the same table from experience, without ; its capital marks a learned estimate. The function below implements the update for any model given as arrays:P[x, a, y] is the probability of moving from x to y under action a, and R[x, a, y] is the reward of that transition.
Code
Code
Deterministic moves
In the deterministic model, each action leads to exactly one next state, so the sum in the update has a single term: .Code
Code
Noisy moves
In the stochastic version of the problem the robot can slip. An action in a nonterminal state moves the robot in the intended direction with probability 0.8, leaves it where it is with probability 0.15, and moves it the opposite way with probability 0.05. The rewards stay attached to the transitions: 5 for any move into the can and 1 for any move into the charger. The update now averages over the three possible next states.Code
Code
References
- Busoniu, L. (2017). Reinforcement learning and dynamic programming using function approximators. DOI
Found an error on this page? Report an issue.

