ML Systems Lab Open interactive version →
Foundational 40 min read mdpmarkovbellmandiscountpomdp

Markov Decision Processes

States, actions, rewards, transitions, discount factor — the formal RL framework

Imagine a robot navigating a grid to reach a goal. At each step it sees its current position, chooses a direction to move, and receives a reward: +1 for reaching the goal, -0.01 for each step taken, -1 for falling into a hole. After moving it ends up in a new position, and the decision problem repeats until the robot reaches a terminal state. That sequence of state-action-reward-state is an episode, and RL's entire job is to find the sequence of actions — the policy — that maximizes total reward across that episode.

The MDP (Markov Decision Process) is the formal language for this. It has five components. The state space S is all possible positions the robot can be in. The action space A is all directions it can move. The transition function T(s, a, s') = P(s' | s, a) is the probability of landing in s' after moving in direction a from state s. The reward function R(s, a, s') is the immediate reward received on that transition. The discount factor γ ∈ [0, 1) controls how much future rewards are worth relative to immediate ones: γ = 0 means the robot cares only about the next step, γ = 0.99 means a reward 100 steps away has decayed to about 37% of its value (0.99^100 ≈ 0.37) — still meaningfully non-negligible, giving an effective planning horizon of roughly 1/(1-γ) ≈ 100 steps, versus a 1-step horizon at γ = 0.

The return G_t = R_{t+1} + γR_{t+2} + γ²R_{t+3} + ... is the discounted sum of all future rewards from time t. The policy π(a | s) is the probability of taking action a in state s. The agent's goal is to find π* — the optimal policy — that maximizes expected return E[G_t] from every starting state.

The Markov property is the key assumption underpinning everything: the next state depends only on the current state and action, not the full history. For the grid robot this holds perfectly — knowing where you are now is enough to navigate. It breaks whenever the current observation is insufficient: a robot that sees only a camera image cannot distinguish a locked door from an unlocked one, because the relevant information — whether a key was picked up earlier — is not in the current frame. The fix is to augment the state representation to include whatever history is needed.

NOT this: RL is only for games and robotics. Any sequential decision problem with delayed feedback can be formulated as an MDP. Ad bidding (state = user context, action = bid amount, reward = revenue), recommendation (state = user history, action = item, reward = click), drug dosing (state = patient vitals, action = drug dose, reward = patient outcome). The MDP framework is the language — the applications are as broad as any problem where you act, observe a result, and act again.

Key points

Takeaway

The MDP is just a formal way of saying: at every step the agent sees a state, picks an action, gets a reward, and ends up somewhere new — and the goal is to find the policy that makes those rewards add up to as much as possible.

Recap

Check your understanding

Q1. Why does the optimal policy for a finite-horizon MDP depend on the time remaining t, while the optimal policy for an infinite-horizon discounted MDP does not?

Q2. Your robot RL agent receives only a camera image as observation. It keeps walking into the same wall repeatedly. What Markov property violation is happening and how do you fix it?

Q3. Why is γ = 0.99 harder to train with than γ = 0.95, even if both converge to a valid solution?

Q4. A product team asks you to deploy an RL agent for content recommendation. Which two of the following are essential MDP design considerations for this system?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →