Uncertainty/Markov Decision Processes

Lesson 4.82,651 words

Markov Decision Processes

When an agent must act repeatedly in a stochastic world, a fixed plan is useless — it needs a policy, an action for every state. The Markov decision process makes this precise with a transition model, a reward, and a discount factor; the Bellman equation characterizes the optimal state utilities, and value iteration and policy iteration solve it.

╌╌╌╌

This builds on Making Decisions: Utility Theory, which set up expected utility, the MEU principle, and the value of information for a single decision. Real agents rarely decide once. They act, watch the stochastic result, and decide again — and because an intended move can slip off course, the agent needs not a plan but a policy: an action for every state it might land in.

Sequential decisions: the Markov decision process

An agent in the world acts, observes the result, and acts again. Because chance can knock it off course, it cannot commit to a fixed sequence of moves; it needs a rule that says what to do in every situation it might end up in. The framework for this is the Markov decision process. The canonical example is a gridworld.1 The agent starts at and can try to move Up, Down, Left, Right. Two terminal squares give reward (at ) and (at ); one square, , is a wall. Every other square gives a small reward , a mild incentive to finish quickly. Motion is stochastic: an action moves the agent in its intended direction with probability , and at a right angle with probability each; bumping a wall leaves it in place.

The 4x3 gridworld. The agent starts bottom-left; terminal squares give +1 and -1; the shaded square is a wall; every other move costs 0.04. An action succeeds with probability 0.8 and slips to a right angle with probability 0.1 each, so an intended Up can drift sideways.

Because outcomes are stochastic, a fixed action sequence is useless — an intended path can slip off course. The agent needs an action for every state it might land in. This bundle of formal parts is a Markov decision process.

A solution is not a plan but a policy , a mapping from every state to an action, with the recommended action in . An optimal policy is one whose expected utility is highest. Its shape depends delicately on : with the mild penalty, the optimal policy in the world is conservative — from it takes the long way around rather than risk slipping into the square. Make the step penalty harsher and the agent sprints for the exit and accepts the risk; make it positive and the agent avoids both exits forever.3

From rewards to the utility of a state

The utility of a policy is the expected utility of the state sequences it generates. To score a sequence, additivity plus a mild stationarity assumption leave essentially one coherent choice: discounted rewards,

where the discount factor trades present against future reward. Discounting also keeps the sum finite over an infinite horizon: with rewards bounded by , the geometric series gives .4 With the utility is undiscounted (additive), which is safe only when the agent is guaranteed to reach a terminal state — a proper policy.

Fixing , define as the (random) state at time under policy . The expected utility of executing starting from is

and is the best policy from . One consequence of infinite-horizon discounting: the optimal policy is independent of the starting state — if two runs ever meet at a state , they have no reason to disagree about what to do from onward. So we drop the subscript and write one .5 The true utility of a state is then the expected utility under the optimal policy, : the long-run reward of being in and behaving optimally thereafter. This is what lets an agent choose actions by one-step MEU,

Note the two different quantities: is the immediate, short-term reward for being in ; is the long-term total reward from onward. In the world the utilities are highest near the exit and fall off with distance, because fewer steps of stand between the agent and the exit.

State utilities U(s) for the 4x3 world with gamma = 1 and R(s) = -0.04. Each cell shows the expected total reward of acting optimally from there; utilities rise toward the +1 exit and are eroded by the per-step cost farther away.

The Bellman equation

The utilities are not independent numbers. Each ties to its neighbors through one recursive constraint: the utility of a state is its immediate reward plus the discounted expected utility of the next state, assuming the agent acts optimally.

For in the gridworld the equation expands over the four actions, each a weighted sum over the three squares its intended-and-slipped motions can reach; plugging in the utilities above shows Up is the best action. The Bellman equation is the fixed-point characterization of , and both algorithms below are just different ways to solve it.

Value iteration

The Bellman equations in unknowns are nonlinear (the max is not linear), so we cannot use linear algebra. Instead, iterate: start with arbitrary utilities, compute the right-hand side, feed it back into the left, and repeat. Each such Bellman update

is applied to every state simultaneously. This is value iteration.7

Algorithm:Value-Iteration(mdp,ε)\textsc{Value-Iteration}(mdp, \varepsilon) — utilities of states by iterated Bellman update
  1. 1
    input: an MDP with states SS, actions A(s)A(s), transitions P(ss,a)P(s' \mid s, a), rewards R(s)R(s), discount γ\gamma
  2. 2
    input: ε\varepsilon, the maximum error allowed in the utility of any state
  3. 3
    U(s)0U'(s) \gets 0 for all sSs \in S
  4. 4
    repeat
  5. 5
    UUU \gets U'
  6. 6
    δ0\delta \gets 0
  7. 7
    for each state sSs \in S do
  8. 8
    U(s)R(s)+γmaxaA(s)sP(ss,a)U(s)U'(s) \gets R(s) + \gamma \max_{a \in A(s)} \sum_{s'} P(s' \mid s, a)\, U(s')
  9. 9
    if U(s)U(s)>δ\lvert U'(s) - U(s) \rvert > \delta then
  10. 10
    δU(s)U(s)\delta \gets \lvert U'(s) - U(s) \rvert
  11. 11
    until δ<ε(1γ)/γ\delta < \varepsilon (1 - \gamma) / \gamma
  12. 12
    return UU

Convergence. View the update as an operator on the whole utility vector, , and measure distance with the max norm. The key fact is that is a contraction by factor :

A contraction has a unique fixed point and drives any two inputs closer on every application, so value iteration converges to the one solution of the Bellman equations whenever .8 Because the true utilities are that fixed point, : the error shrinks by at least each sweep, so convergence is exponential. The termination test guarantees the returned utilities are within of the true ones. In practice the policy extracted by one-step lookahead becomes optimal well before the utilities themselves converge — the exact magnitudes stop mattering once one action clearly dominates.

Utilities converging under value iteration in the 4x3 world. Every state starts at zero; the update propagates reward outward from the +1 exit, and each state's estimate climbs to its true utility, states nearer the goal settling first.

Policy iteration

Value iteration converges on the utilities, then reads off a policy — but often the policy stops changing long before the utilities settle, since only the ordering of actions matters. Policy iteration exploits this by working on the policy directly, alternating two steps from an initial policy :9

  • Policy evaluation: given , compute , the utility of each state if were executed.
  • Policy improvement: compute a new MEU policy by one-step lookahead on .

The evaluation step is the reason this is cheap. With the policy fixed, the action in each state is determined, so the max vanishes and the Bellman equation becomes linear:

For states these are linear equations in unknowns, solvable exactly in by standard linear algebra — or approximately, by a few simplified Bellman sweeps with the policy held fixed (modified policy iteration). The loop terminates when improvement changes nothing; the utilities are then a fixed point of the Bellman update, so the policy is optimal. Since there are finitely many policies and each round strictly improves, termination is guaranteed.

Algorithm:Policy-Iteration(mdp)\textsc{Policy-Iteration}(mdp) — optimal policy by evaluate-then-improve
  1. 1
    input: an MDP with states SS, actions A(s)A(s), transitions P(ss,a)P(s' \mid s, a)
  2. 2
    U(s)0U(s) \gets 0 for all sSs \in S
  3. 3
    π\pi \gets a random policy
  4. 4
    repeat
  5. 5
    UPolicy-Evaluation(π,U,mdp)U \gets \textsc{Policy-Evaluation}(\pi, U, mdp)
  6. 6
    unchangedtrueunchanged \gets \textbf{true}
  7. 7
    for each state sSs \in S do
  8. 8
    aarg maxaA(s)sP(ss,a)U(s)a^\ast \gets \argmax_{a \in A(s)} \sum_{s'} P(s' \mid s, a)\, U(s')
  9. 9
    if sP(ss,a)U(s)>sP(ss,π(s))U(s)\sum_{s'} P(s' \mid s, a^\ast)\, U(s') > \sum_{s'} P(s' \mid s, \pi(s))\, U(s') then
  10. 10
    π(s)a\pi(s) \gets a^\ast
  11. 11
    unchangedfalseunchanged \gets \textbf{false}
  12. 12
    until unchangedunchanged
  13. 13
    return π\pi

Value iteration and policy iteration are the same idea at different granularities: both alternate estimating utilities and improving the policy. Loosening the schedule — updating any subset of states, with either kind of update — gives asynchronous dynamic programming, which converges under mild conditions and lets an agent concentrate work on the states a good policy actually visits.

Partial observability: the belief-state MDP

MDPs assume the environment is fully observable — the agent always knows which state it is in. Drop that and you get a partially observable MDP (POMDP), with all the MDP elements plus a sensor model giving the probability of observing evidence in state . Now the agent cannot execute , because it does not know .10

The fix is to act on what the agent does know: its belief state , a probability distribution over the actual states. After doing action and observing , the belief updates by filtering, . The fundamental result is that the optimal action depends only on the current belief state — so an optimal policy is a map from beliefs to actions. This converts the POMDP into an ordinary MDP over the (continuous) belief-state space, with its own transition model and reward ; solving that belief-MDP solves the original POMDP.11 The difficulty is that the belief space is continuous and high-dimensional, so exact POMDP solving is very hard (PSPACE-hard); practical agents use approximate look-ahead search over dynamic decision networks.

Bandits, regret, and scalable MDP solvers

The classical picture in this lesson — a fixed, fully known model, solved offline to optimality by dynamic programming — is only the base of a large modern literature. Three strands extend it in directions the textbook treatment gestures at but does not develop.

The multi-armed bandit is the MDP stripped to a single state: actions (arms), each returning a reward from an unknown distribution, and the agent wants to maximize total reward over pulls. There is no transition dynamics, only the tension between exploiting the arm that has looked best so far and exploring arms whose value is still uncertain — the exploration/exploitation trade-off in its purest form. The right yardstick is regret, the shortfall against always pulling the best arm. Lai and Robbins (1985) proved that no strategy can do better than regret growing as , and that this bound is achievable.12 The upper confidence bound rule UCB1 attains it by adding an exploration bonus to each arm's empirical mean, picking so that seldom-tried arms stay attractive until their estimates sharpen (Auer, Cesa-Bianchi, and Fischer, 2002).13 The Bayesian alternative, Thompson sampling, keeps a posterior over each arm's value and pulls in proportion to the posterior probability that the arm is best; it is decades old (Thompson, 1933) but its strong empirical and theoretical performance was only established recently.14 Bandits are the theory behind A/B testing, ad selection, and clinical-trial design, and are the natural setting in which VPI becomes a live, repeated decision rather than a one-shot calculation.

When the state space is astronomically large, value and policy iteration over an explicit table are hopeless, and the standard tool is sampling. Monte-Carlo tree search (MCTS) with the UCT rule — UCB applied to the tree of a sequential decision problem — estimates action values by rolling out random continuations and concentrating simulations on promising branches (Kocsis and Szepesvári, 2006).15 Combined with deep neural networks that supply value and policy priors, MCTS drives AlphaGo (Silver et al., 2016) and its successors, which solve enormous game-tree MDPs that no exact method could touch.16 The same model-based planning appears in AlphaZero and MuZero, where the transition model itself is learned, closing the loop back to reinforcement learning.

POMDP solving at scale has its own approximate methods. Exact belief-space value iteration is intractable, but point-based value iteration (Pineau, Gordon, and Thrun, 2003) keeps the piecewise-linear value function only at a sampled set of reachable belief points, and the online solver POMCP (Silver and Veness, 2010) runs Monte-Carlo tree search directly in belief space using particle filters. These turn the belief-MDP idea of this lesson from a theoretical reduction into agents that run on real robots.

The common thread is that every extension here keeps the MEU objective and the Bellman structure intact, and only changes how the intractable expectation or maximization is approximated — by confidence bounds, by sampling, or by learned function approximators.

The bridge to reinforcement learning

Everything above assumes the agent is handed the MDP — it knows and and merely computes an optimal policy. That is planning, not learning. The whole apparatus carries over verbatim to reinforcement learning, with one thing removed: the model.

The objects are identical — states, actions, a transition model, a reward, a discount, policies, the utility of a state, the Bellman equation. Value iteration and policy iteration reappear under the name dynamic programming, the model-based backbone of RL. What changes is only that the expectations can no longer be computed in closed form: without , the agent must sample the transition by acting, and average the results over time. Monte-Carlo and temporal-difference methods are those same Bellman updates with the unknown expectation replaced by a sampled estimate. The MDP theory of this lesson is RL with a known model; every RL algorithm is a way of running these same updates while estimating and from experience.

Footnotes

  1. AIMA, §17.1 — Sequential Decision Problems: the gridworld, the stochastic transition model (0.8 intended, 0.1 to each side), the per-step reward, and the terminal states.
  2. AIMA, §17.1 — a Markov decision process is a set of states with an initial state, a set of , a Markovian transition model , and a reward function .
  3. AIMA, §17.1 — policies and optimal policies: a policy maps every state to an action; the optimal policy maximizes expected utility, and its risk profile depends on the sign and magnitude of for nonterminal states.
  4. AIMA, §17.1.1 — Utilities over time: stationarity forces either additive or discounted rewards; the discounted sum is finite for , bounded by ; proper policies permit .
  5. AIMA, §17.1.2 — Optimal policies and the utilities of states: ; with infinite-horizon discounting the optimal policy is independent of the start state, and enables action selection by one-step MEU.
  6. AIMA, §17.2.1 — The Bellman equation for utilities: ; the true utilities are its unique solution, and the makes the system nonlinear.
  7. AIMA, §17.2.2 — The value iteration algorithm: the Bellman update applied simultaneously to all states, iterated to a fixed point, with the termination test .
  8. AIMA, §17.2.3 — Convergence of value iteration: the Bellman operator is a contraction by in the max norm, so it has a unique fixed point and value iteration converges exponentially fast for .
  9. AIMA, §17.3 — Policy Iteration: alternating policy evaluation (linear, , or approximate via modified policy iteration) with policy improvement by one-step lookahead; termination when the policy stops changing.
  10. AIMA, §17.4 — Partially Observable MDPs: a POMDP adds a sensor model ; the agent cannot observe its state, so the optimal action depends on the belief state rather than the physical state.
  11. AIMA, §17.4.1–17.4.2 — the belief-state update , the belief-space transition model and reward , and the reduction of a POMDP to an MDP over the continuous belief space.
  12. Lai, T. L., and Robbins, H. (1985), Asymptotically efficient adaptive allocation rules, Advances in Applied Mathematics 6(1): 4–22 — established the lower bound on the regret of any consistent bandit allocation rule and an asymptotically matching strategy.
  13. Auer, P., Cesa-Bianchi, N., and Fischer, P. (2002), Finite-time Analysis of the Multiarmed Bandit Problem, Machine Learning 47: 235–256 — the UCB1 algorithm, which achieves regret uniformly over time by an additive confidence bonus.
  14. Thompson, W. R. (1933), Biometrika 25: 285–294 introduced posterior sampling; near-optimal regret guarantees were shown much later, e.g. Agrawal, S., and Goyal, N. (2012), Analysis of Thompson Sampling for the Multi-armed Bandit Problem, COLT.
  15. Kocsis, L., and Szepesvári, C. (2006), Bandit based Monte-Carlo Planning, ECML — the UCT algorithm applying UCB to the search tree, the basis of modern Monte-Carlo tree search.
  16. Silver, D. et al. (2016), Mastering the game of Go with deep neural networks and tree search, Nature 529: 484–489 — combined Monte-Carlo tree search with deep value and policy networks to defeat a professional Go player.

╌╌ END ╌╌