A warehouse robot can work or recharge. Working pays more now, but it can drain the battery and make later steps less productive, so the better action depends on where it leads and not only on its immediate reward. A bandit, whose actions never change the situation, cannot describe this. This lesson specifies the problem as a Markov decision process, measures long-run reward by the discounted return, computes the value of a fixed policy from the Bellman expectation equation, and checks that policy against the Bellman optimality equation. The robot and all its numbers are constructed for illustration.
Key terms
Markov decision process
Definition A finite Markov decision process, or MDP, consists of a finite set of states, a finite nonempty set of actions for each state , transition probabilities and rewards. At each step the agent observes the state and chooses an action in , and then it receives a reward and moves to the next state . The transition probability
is the probability of moving to state when action is taken in state , the same at every step. For each pair these numbers are nonnegative and add to over . On this page the reward of a step is a fixed number that depends only on the current state and action and is received on the transition. More general MDPs let the reward depend on the next state or be random, and then denotes the expected reward. The Markov property is the assumption that, given the current state and action, the next state and reward do not depend on anything earlier. For every history of earlier states, actions and rewards that has positive probability,
and the same holds for the reward.
In plain words An MDP is the complete rulebook of a sequential decision problem. It says what the agent observes, what it can do, what each choice pays and how likely each next state is. Unlike in a bandit, an action changes the next state and with it the rewards available later. The Markov property says that the current state carries everything about the past that matters for what happens next. It is an assumption about the chosen description of the state, not a fact about the world, and a description that leaves out something relevant can break it. The reward also defines the goal. An agent that maximizes reward pursues exactly what the reward measures, which need not include costs, safety or effects on people that the reward leaves out.
Example A constructed warehouse robot has the states charged and low and the actions work and recharge. The table gives the reward and the next-state probabilities for every state and action.
| State | Action | Reward | Next state charged | Next state low |
|---|---|---|---|---|
| charged | work | |||
| charged | recharge | |||
| low | work | |||
| low | recharge |
The probabilities in each row add to . The reward for recharging from low is a modeled cost, not a measured amount of money. If the chance of running low after work also rose with the number of consecutive work steps, for example through heat, the current state and action would no longer fix the next-state probabilities, and this two-state model would break the Markov property. Adding the missing information, such as a temperature level, to the state could restore it.
Policy
Definition A policy assigns to each state a probability distribution over the actions in . On this page a policy depends only on the current state, so at every step and whatever happened earlier,
A deterministic policy puts probability on one action in each state. Together with the MDP and the distribution of the starting state, a policy fixes the probability of every trajectory . For instance, the first two states and actions are with probability
In plain words A policy is the agent’s decision rule. It decides which actions appear in the data and, through the transitions, which states are visited. Data collected under one policy describe that policy’s trajectories, consecutive steps depend on each other, and actions the policy never takes leave no outcomes at all. A random split of logged steps into training and test rows cannot reveal what another action would have done, or which states a different policy would reach.
Example The policy works when charged and recharges when low. Starting charged, one possible trajectory works and drops to low, which has probability , then recharges and returns to charged with probability , then works again. Its first three rewards are , and . A stochastic policy might instead recharge from low with probability and work with probability . A policy that always works never produces a recharge step, so its data say nothing about the reward or the transitions of recharging.
Discounted return
Definition For a discount factor , the return from step is the next reward plus times the reward after it, plus times the one after that, and so on,
A continuing task, which never ends, assumes bounded rewards, , and . Then the series converges and . In an episodic task, which ends when it reaches a terminal state at step , the sum stops with the reward and all later rewards count as . There is also allowed when every episode ends within a bounded number of steps. In both cases the return satisfies, at every step of a continuing task and every step before the end of an episode,
with at the end of an episode.
In plain words The return adds up all future rewards, each weighted by how far ahead it comes. With only the next reward counts, and with close to distant rewards count almost as much as near ones, so the choice of is part of the objective. The return is a random variable. One run of the process gives one realized value, and another run from the same state can give a different one. Neither a familiar value of nor a large total reward shows that the objective captures every real consequence.
Example The robot task never ends, so it uses . Its rewards lie between and , so every return lies between and . Along the trajectory of the policy example, with rewards , and , the first three terms of the return are , and , and
This is a partial sum along one realized path. The full return adds , which depends on how the path continues, so it lies between and .
Value function
Definition For a policy in an MDP with bounded rewards and , or in an episodic task as above, the state-value function of is
the expected return when the process is in state and the agent follows from then on. The action-value function
is the expected return when the agent takes action in state and follows afterward. Neither depends on , because the MDP and the policy are the same at every step. The two are linked by , and a terminal state has value .
In plain words A value is an average over all the paths a policy can produce from a state, weighted by their probabilities, and not the return of one path. Values belong to a policy, so changing the policy changes them. Three kinds of numbers need to be kept apart. A reward is paid on one step, a value is an expected discounted total, and an action probability is part of the policy.
Example The policy that always recharges keeps a charged robot charged with reward on every step, so its value at charged is . From low it pays once and then forever, so its value at low is . The policy that always works keeps a low robot low with reward on every step, so with its value at low is
For the always-recharge policy, the action value of working at low is , since the robot stays low and then follows that policy. It is larger than the policy’s own value at low, so a better first action exists there.
Bellman expectation equation
Definition Let be a policy in a finite MDP with . For every state and action ,
and . Substituting the first equation into the second gives one linear equation for each state, the Bellman expectation equation for . It follows from and the Markov property, which make the expected return after a move to equal to . The value function is the unique solution of this system. It can also be approached by synchronous updates. Starting from any values , each sweep computes for every state from the right sides of these equations, with the previous values in place of . The sweeps converge to , because each one multiplies the largest error over the states by a factor of at most .
In plain words The value of a state is the expected immediate reward plus the discounted expected value of wherever the policy leads next. The policy is fixed, so the equation averages over its actions with their probabilities and over the next states with their transition probabilities, and nothing is maximized. Solving it requires the transition probabilities and rewards. An exact solution for an inaccurate model describes the model and not the real system, and when only sampled transitions are available the values must be learned from experience, as in temporal-difference learning.
Example Take the policy , which works when charged and recharges when low, with , and write and for its values at charged and low. The equations are
The first averages the two possible next states, and the second has a certain next state. Substituting the second into the first gives , so . Hence and . Starting instead from the values at (charged, low), the synchronous updates give and then , each computed from the previous pair only. Their largest errors , and shrink by at least half at every sweep.
Bellman optimality equation
Definition In a finite MDP with , the optimal value function is the largest value any policy achieves from state . With
the Bellman optimality equation states that for every state
and is the unique solution of these equations. A policy is optimal, with in every state, exactly when in every state it gives all its probability to actions that attain this maximum, so some deterministic policy is optimal. Written for action values alone, the equation reads
In plain words The expectation equation averages over the actions of a fixed policy, while the optimality equation takes the best action in each state. An action with a worse immediate reward can still be best if it leads to better states. The maximum runs over the agent’s actions only. The next state is still averaged with its transition probabilities, because the environment decides where the process goes. Optimal means optimal for the stated rewards and discount factor, and a different reward definition can lead to a different optimal policy.
Example At the values and of , the four action values are as follows, where is the expected next value after working while charged.
| State | Action | Action value |
|---|---|---|
| charged | work | |
| charged | recharge | |
| low | work | |
| low | recharge |
In each state the largest action value equals the value of , so these values satisfy the optimality equation, the optimal values are and , and is optimal. At low, recharging pays now, less than the of working, yet it is the better action. The other three deterministic policies agree. Working in both states gives the values at charged and at low, recharging at charged and working at low gives and , and recharging in both states gives and , so none beats in either state.
Check yourself
- An episode gives the rewards , and and then reaches a terminal state. Find its return from the start with . Then explain why the continuing robot task cannot use with the policy .
Show the answer
The episode ends after the third reward, so the sum has three terms,
Under the robot earns at every step in charged and at every step in low, and every step in low is followed by a step in charged. With the rewards along every path therefore add up to infinity, and the values are not finite numbers. The Bellman expectation equations and then have no solution at all, since substituting the second into the first gives . A task that never ends needs .
- In some state the policy’s action pays reward and leads to a state with value with probability and to a state with value with probability . With , compute the Bellman expectation backup for this state. A classmate uses the larger next value , because the Bellman optimality equation takes a maximum. What is wrong?
Show the answer
The expected next value is , so the backup is
The classmate’s value is wrong in both equations. The environment, not the agent, decides which next state occurs, so both the expectation and the optimality equation average over next states with their transition probabilities. The maximum in the optimality equation runs over the actions available in the current state.
- A company logs a year of steps of the robot under the policy that always works, splits the logged steps at random into training and test rows, and wants to estimate the value of . What can these data show, and what would be needed?
Show the answer
The policy recharges whenever the robot is low, but the logs contain no recharge steps, so they hold no information about the reward or the next state after recharging. No split of the rows can create those outcomes. The logs also reflect the states that always working produces. Working while low keeps the robot low, so after the first few steps nearly every logged step is in low, a distribution that would not produce. Consecutive steps of one trajectory are also dependent, so a random split places closely related steps in both parts.
The data can estimate what working does, for example the value of always working, which is at low. To evaluate the data must include recharge actions taken in the low state, for example from a policy that sometimes explores, or the transitions must come from a model whose assumptions are trusted. The best evidence is to run itself and measure its returns.