Search

Search papers and lessons

Markov Decision Process

Level 3 · 13 min read

A Markov decision process is a model of sequential choice: an agent picks actions in states, the world responds with a random next state and a reward, and the next state depends only on the current state and action.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Stochastic processes
  • Reinforcement learning
  • Discrete math
  • Sign in to see your progress

TL;DR

A Markov decision process (MDP) is the standard mathematical model for a decision maker acting over time in a world that is partly random. At each step the agent sees a state, picks an action, receives a reward, and the world moves to a new state according to probabilities that depend only on the current state and the action taken. Choosing well means picking actions that earn the most reward over the long run, not just right now.

The name combines two ideas. The world is a Markov chain once the agent's choices are fixed, so the future depends only on the present. The "decision" part adds the agent, whose actions steer the chain.

Where you'll see it: in reinforcement learning, where game-playing agents, robot controllers and the fine-tuning of language models are all framed as MDPs, and in inventory, pricing and maintenance planning.

Intuition

A game of states, moves and rewards

Imagine a delivery robot in a small warehouse. Its state is where it is and how much battery it has. Each step it chooses an action: move left, move right, or recharge. Moving costs a little energy, recharging costs time, and delivering a parcel pays a reward. Where the robot ends up is partly random, because the floor is slippery and the wheels sometimes slide.

The MDP is the bookkeeping for this story. It names the possible states, the possible actions, the chance of each outcome, and the reward. It gives no answer by itself. It only says what the problem is, so that a method can search for a good plan.

Why the Markov part matters: if the state already records the battery level and the position, then knowing the whole history of the robot adds nothing to predicting what happens next. The state is a summary of everything relevant. That summary is what makes planning possible. Without it, the robot would have to remember every past move before it could decide, and the problem would balloon.

The key trade-off is between now and later. Recharging now costs a reward, but it keeps the robot alive for the deliveries that come after. A good policy has to see that link, which is why the reward is summed over time rather than read off one step at a time.

flowchart LR
  A[State A] -- "go, reward 1" --> B[State B]
  A -- "stay, reward 0" --> A
  B -- "stay, reward 2" --> B
  B -- "go, reward 0" --> A

The diagram is the smallest interesting MDP: two states, two actions each. Arrows show which state each action leads to. The worked example below uses exactly this one.

The math

Definition

Definition: Markov decision process

A Markov decision process is a tuple (S,A,P,R,γ)(\mathcal{S}, \mathcal{A}, P, R, \gamma), where

  • S\mathcal{S} is the set of states,
  • A\mathcal{A} is the set of actions (in some states only a subset is allowed, which we ignore here),
  • P(s′∣s,a)P(s' \mid s, a) is the probability that the next state is s′s' when the agent takes action aa in state ss,
  • R(s,a)R(s, a) is the expected reward received for taking action aa in state ss,
  • γ∈[0,1)\gamma \in [0, 1) is the discount factor.

Read the bar in P(s′∣s,a)P(s' \mid s, a) as "given that". The probabilities for each state and action must add to 1 over s′s', just like the rows of a Markov chain transition matrix. The Markov property is built in: PP looks only at ss and aa, never at the earlier history. Removing the actions leaves a plain Markov reward process; fixing a rule for choosing actions also leaves one.

A rule for choosing actions is called a policy π\pi. A deterministic policy maps each state to one action, a=π(s)a = \pi(s). A stochastic policy gives a probability π(a∣s)\pi(a \mid s) for each action. Fixing π\pi turns the MDP into a Markov chain on states, with transition probabilities Pπ(s′∣s)=∑aπ(a∣s)P(s′∣s,a)P_\pi(s' \mid s) = \sum_a \pi(a \mid s) P(s' \mid s, a).

Return and the discount factor

The quantity to maximise is the return, the discounted sum of future rewards starting from time tt:

Gt=Rt+1+γRt+2+γ2Rt+3+⋯=∑k=0∞γkRt+k+1.G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1}.

A reward kk steps in the future is worth γk\gamma^k of its face value today. With γ=0.9\gamma = 0.9, a reward ten steps away counts for about 35 percent of itself; with γ=0.5\gamma = 0.5, it counts for about 0.1 percent. The discount keeps the infinite sum finite when rewards are bounded, and it expresses a preference for sooner over later. Since γ<1\gamma \lt 1, the geometric series converges to at most Rmax⁡/(1−γ)R_{\max}/(1-\gamma) when every reward is at most Rmax⁡R_{\max}.

0510152000.20.40.60.81k (steps into the future)weight gamma^k
  • gamma = 0.9
  • gamma = 0.5
The weight a reward k steps away receives. A smaller gamma makes the agent short-sighted: the weights die away within a few steps.

The value function

The value of a state under a policy is the expected return when starting there and following π\pi:

vπ(s)=Eπ[Gt∣St=s].v_\pi(s) = \mathbb{E}_\pi\left[ G_t \mid S_t = s \right].

The expectation (see Expected Value) is over the randomness in the policy and the transitions. Because the return from t+1t+1 onwards has the same form as the return from tt, the value satisfies a recursion. Splitting off the first reward and the first transition gives

vπ(s)=∑aπ(a∣s)[R(s,a)+γ∑s′P(s′∣s,a) vπ(s′)].v_\pi(s) = \sum_{a} \pi(a \mid s) \Big[ R(s, a) + \gamma \sum_{s'} P(s' \mid s, a)\, v_\pi(s') \Big].

This is the Bellman expectation equation. It says the value of ss is the average, over actions and next states, of the immediate reward plus the discounted value of where you land. The optimal value v∗(s)=max⁡πvπ(s)v^*(s) = \max_\pi v_\pi(s) satisfies the same idea with a maximum over actions, the Bellman optimality equation:

v∗(s)=max⁡a[R(s,a)+γ∑s′P(s′∣s,a) v∗(s′)].v^*(s) = \max_{a} \Big[ R(s, a) + \gamma \sum_{s'} P(s' \mid s, a)\, v^*(s') \Big].

Solving this system tells you the best achievable value in every state, and reading off the maximising action in each state gives an optimal policy.

Two solution methods

Value iteration applies the right-hand side repeatedly, starting from any guess v0v_0, and vk+1v_{k+1} is the result of one sweep. Because the update is a contraction with factor γ\gamma, the error shrinks by at least that factor each sweep. Policy iteration instead evaluates a fixed policy exactly (a linear system), then improves the policy greedily, and repeats. Both reach the optimum for finite MDPs.

Worked examples

Example
A two-state toy problem, by hand

Take the diagram above with γ=0.5\gamma = 0.5. In state A, "stay" gives reward 0 and keeps you in A, while "go" gives reward 1 and moves you to B. In state B, "stay" gives reward 2 and keeps you in B, while "go" gives reward 0 and moves you to A. Everything is deterministic, so PP is just 0 or 1.

  1. Guess a policy: in B stay, in A go. Then the value of B is v(B)=2+0.5 v(B)v(B) = 2 + 0.5\, v(B), so v(B)=4v(B) = 4.
  2. In A, going to B gives v(A)=1+0.5⋅4=3v(A) = 1 + 0.5 \cdot 4 = 3.
  3. Check the guess. In A, "stay" would give 0+0.5⋅3=1.50 + 0.5 \cdot 3 = 1.5, which is less than 3, so "go" is right. In B, "go" would give 0+0.5⋅3=1.50 + 0.5 \cdot 3 = 1.5, less than 4, so "stay" is right.
  4. The guess is consistent with the Bellman optimality equation, so v∗(A)=3v^*(A) = 3 and v∗(B)=4v^*(B) = 4.

Now run value iteration from v0=(0,0)v_0 = (0, 0) to see the convergence. Each sweep applies both maxima.

  1. Sweep 1: v1(A)=max⁡(0,1)=1v_1(A) = \max(0, 1) = 1 and v1(B)=max⁡(2,0)=2v_1(B) = \max(2, 0) = 2.
  2. Sweep 2: v2(A)=max⁡(0.5⋅1,1+0.5⋅2)=2v_2(A) = \max(0.5 \cdot 1, 1 + 0.5 \cdot 2) = 2 and v2(B)=max⁡(2+0.5⋅2,0.5⋅1)=3v_2(B) = \max(2 + 0.5 \cdot 2, 0.5 \cdot 1) = 3.
  3. Sweep 3: v3(A)=2.5v_3(A) = 2.5 and v3(B)=3.5v_3(B) = 3.5.
  4. Sweep 4: v4(A)=2.75v_4(A) = 2.75 and v4(B)=3.75v_4(B) = 3.75.

The distance from B's optimal value 4 is 2, 1, 0.5, 0.25 after each sweep: it halves every time, which is the factor γ=0.5\gamma = 0.5 at work. Interpretation: the optimal plan is to walk to B once and then sit there collecting 2 per step. Staying in A forever would pay 0 at every step, so leaving is always better.

Example
Should a subscription service send a nudge?

A streaming service has two customer states: Free (F) and Paid (P). From Paid, a customer pays 10 per month and cancels with probability 0.2 each month. From Free, a customer earns nothing. Each month the service can either "nudge" (an email campaign that costs 1 per free customer) or "hold" (do nothing). A nudge converts a Free customer with probability 0.3 instead of 0.1. Paid customers are unaffected by the choice. Use γ=0.9\gamma = 0.9.

Transition probabilities and rewards:

StateActionNext stateProbabilityReward
FnudgeP0.3-1
FnudgeF0.7-1
FholdP0.10
FholdF0.90
PanyP0.810
PanyF0.210

Compare two fixed policies. Each is a Markov chain with rewards, so the value satisfies a linear system v=R+γPπvv = R + \gamma P_\pi v.

  1. Policy "always nudge". Write vFv_F and vPv_P for the two values. Then vF=−1+0.9(0.3 vP+0.7 vF)v_F = -1 + 0.9(0.3\, v_P + 0.7\, v_F) and vP=10+0.9(0.8 vP+0.2 vF)v_P = 10 + 0.9(0.8\, v_P + 0.2\, v_F).
  2. Rearrange the first: 0.37 vF=−1+0.27 vP0.37\, v_F = -1 + 0.27\, v_P. Rearrange the second: 0.28 vP=10+0.18 vF0.28\, v_P = 10 + 0.18\, v_F.
  3. Substitute. The solution is vP=64v_P = 64 and vF=44v_F = 44.
  4. Check: 10+0.9(0.8⋅64+0.2⋅44)=10+0.9⋅60=6410 + 0.9(0.8 \cdot 64 + 0.2 \cdot 44) = 10 + 0.9 \cdot 60 = 64, and −1+0.9(0.3⋅64+0.7⋅44)=−1+0.9⋅50=44-1 + 0.9(0.3 \cdot 64 + 0.7 \cdot 44) = -1 + 0.9 \cdot 50 = 44.
  5. Policy "always hold". The same steps give vF=919vPv_F = \tfrac{9}{19} v_P and vP=1900/37≈51.35v_P = 1900/37 \approx 51.35, so vF=900/37≈24.32v_F = 900/37 \approx 24.32.

Interpretation: nudging costs 1 a month while a customer is free, but it nearly doubles the value of a free customer (44 against 24.3). It also lifts the value of a paid customer (64 against 51.35), because a paid customer who cancels becomes a free customer who can be won back. The total value is higher under nudging in both states, so a policy that nudges free customers dominates. These are the only two deterministic policies, so nudging is the optimal policy here. The same machinery that solved the toy problem answers a yes-or-no business question.

Tradeoffs and failure modes

An MDP is the right model when the problem has actions that change the state, outcomes that are random, and a reward that depends on a sequence of choices. It is the wrong model when the agent cannot see the state, when the transition probabilities are unknown and cannot be learned, or when the reward is only known at the end and cannot be attributed to earlier steps.

SituationProblemBetter choice
The agent sees only part of the state (for example, a camera)The Markov property fails; the observation is not enough to predict the futurePartially observable MDP, or a recurrent policy that keeps memory
The model PP and RR are unknown, but you can act and observeDynamic programming needs PP and RRModel-free reinforcement learning such as [[q-learning
The state or action space is huge (images, text)Tables of values cannot be storedFunction approximation, such as a neural network for the value or the policy
The reward is rare and far in the futureLearning is slow and noisyShaped rewards, or a discount that is closer to 1 with more samples
The discount is too small (for example 0.5)The agent ignores consequences a few steps awayRaise γ\gamma toward 0.99 for long-horizon tasks
The reward is sometimes the wrong proxy (for example clicks)The agent learns to game the proxyRevisit the reward; treat it as part of the design, not a fixed fact

A common failure in practice is an agent that is perfectly optimal for the MDP you wrote down and useless for the world you meant. The model is only as good as its states, probabilities and rewards. Check each assumption before trusting the policy.

History

The formal model comes from operations research. Richard Bellman introduced the dynamic-programming approach to sequential decisions in the early 1950s, and in 1957 he wrote a paper on what he called a Markovian decision process, presenting the optimality equation that now carries his name. The problem he was solving was how to plan multi-stage decisions under uncertainty, such as the stock of a warehouse or the routing of a process, where the same subproblems came back again and again.

Ronald Howard followed in 1960 with a book that introduced policy iteration, a method that alternates between evaluating a policy and improving it. That gave the field its practical algorithms. Martin Puterman's 1994 textbook is the standard reference for the theory of discounted and infinite-horizon problems.

The model entered machine learning through reinforcement learning. Chris Watkins's 1989 thesis on learning from delayed rewards connected the MDP to learning without a known model, which led to Q-learning. Richard Sutton and Andrew Barto's textbook made the MDP the common language of the field, and later work combining these ideas with deep networks made it central to modern game-playing and control agents.

Check yourself

QuestionIn an MDP, what does the Markov property say about the transition probabilities P(s′∣s,a)P(s' \mid s, a)?Show answer

It says the probability of the next state depends only on the current state ss and the action aa. The earlier history of states and actions adds nothing once ss and aa are known. That is what lets the model be written as one table of probabilities, and what makes the dynamic-programming equations valid.

QuestionWith γ=0.9\gamma = 0.9, what weight does a reward received 5 steps in the future get in the return? Give a number to two decimal places.Show answer

The weight is γ5=0.95\gamma^5 = 0.9^5. Computing it step by step: 0.92=0.810.9^2 = 0.81, 0.93=0.7290.9^3 = 0.729, 0.94=0.65610.9^4 = 0.6561, 0.95=0.590490.9^5 = 0.59049. So the weight is about 0.59.

QuestionIn the two-state toy problem, why is 'stay in A' never optimal even though it costs nothing?Show answer

Staying in A gives reward 0 forever, so its value is 0+0.5⋅v(A)0 + 0.5 \cdot v(A), which can only be 0 if v(A)v(A) is 0. Going to B gives reward 1 once and then reward 2 per step thereafter, which is worth 3 from A. Any positive reward available later beats a permanent zero, so the optimal action in A is to go.

QuestionWhy might a designer choose a larger discount factor, say 0.99, rather than 0.5 for a long-running robot?Show answer

A larger γ\gamma keeps distant rewards meaningful. With 0.5, rewards more than a few steps away are almost ignored, so the robot would never plan to recharge early or to pursue a delivery that takes many moves. With 0.99 the same rewards still count substantially, which matches a task whose payoff depends on a long sequence of actions. The cost is that learning and planning take longer, because the effective horizon is about 1/(1−γ)1/(1-\gamma) steps, here 100.

QuestionA subscription firm's model says a nudge always pays off, but the firm's actual nudges have a 0.1 chance of conversion. What should the firm check before trusting the MDP policy?Show answer

It should check the transition probabilities against data. The policy's value depends directly on the conversion probability in the model, so if the model assumed 0.3 and reality is 0.1, the nudge's advantage may vanish or reverse. The firm should estimate the conversion rate from a controlled test, rerun the policy evaluation with the measured value, and see whether the ranking of the two policies changes.

Sources