skip to content

MDPs and Reward Design

The MDP tuple of states, actions, transitions and reward, plus discounting, episodic versus continuing tasks, and how a badly written reward gets hacked by the agent that optimises it.

on this pageshow

questions

5

What are the five components of a Markov decision process?

level: juniorimportance: must knowfreq 72%

answer

  1. five moving parts, one tuple
  2. where you are, what you can do
  3. environment supplies two of them
  4. probability of the next state
  5. how much a later reward counts

basics

~20 s

An MDP is written as states, actions, a transition function giving the probability of the next state, a reward function, and a discount factor gamma. Together they define a sequential decision problem an agent solves by choosing actions.

solid answer

~50 s

An MDP is the standard way to write down a sequential decision problem, and it has five parts. A set of states `S` describing the situations the agent can be in; a set of actions `A` it can take; a transition function `P(s' | s, a)` giving the probability of each next state; a reward function `R(s, a, s')` giving the scalar feedback the environment emits; and a discount factor `gamma` in `[0, 1]` setting how much a later reward is worth now. The word *Markov* is the assumption that binds them: the next state and reward depend only on the current state and action, not on how the agent got there. The agent's job is to choose actions maximising expected discounted return. For a warehouse parcel robot, states are position and load, actions are moves and pickups, reward is +1 per parcel delivered.

go deeper

for a junior

Be ready to list all five parts without hesitating and say one sentence about each. Naming states, actions and reward but forgetting transitions and gamma is the usual stumble at this level.

for a middle

Expect to be asked to formulate a described business problem as an MDP on the spot: name its states, its action set, where the stochasticity lives, and what the reward should be.

for a senior

Show that you know the hard part is the mapping, not the tuple. Talk about how you would decide the action granularity and the time step, and why a badly chosen state or step size makes the whole formulation useless.

for a principal

Own the framing decision itself. Argue when a problem genuinely warrants a sequential formulation versus a simpler one-shot prediction, and be explicit about what the MDP abstraction hides from stakeholders.

## What an MDP is for Supervised learning asks "given this input, what is the label?" A **sequential decision problem** asks something harder: "given where I am, what should I *do*, knowing that my action changes where I end up next?" A **Markov decision process (MDP)** is the standard mathematical container for that second question. Almost every reinforcement-learning algorithm assumes the problem has been written in this form, so interviewers start here before touching any algorithm. ## The five components An MDP is the tuple `(S, A, P, R, gamma)`. **1. States, `S`.** The set of situations the agent can be in. A state is meant to be a complete-enough description of the world for the decision at hand — position, load, temperature, inventory level, whatever the decision turns on. States can be finite (grid squares) or continuous (a temperature reading). **2. Actions, `A`.** What the agent can choose to do. Actions may depend on the state — a robot holding nothing cannot choose "drop the parcel". Like states, actions can be discrete (move north, pick up) or continuous (set the fan speed to 62%). **3. Transition function, `P(s' | s, a)`.** The probability of landing in state `s'` given that the agent took action `a` in state `s`. This is the *environment's* dynamics, not the agent's. It is what makes the problem stochastic: telling a robot to move forward might succeed 95% of the time and slip sideways the rest. If the environment is deterministic, `P` puts probability 1 on a single successor — determinism is a special case, not a requirement. **4. Reward function, `R(s, a, s')`.** A single scalar number the environment emits after each transition. It is the *entire* specification of what the agent should want. There is no separate "goal" object in an MDP — the goal is whatever maximises accumulated reward. Reward is emitted by the environment, not chosen by the agent, and designing it is the hardest part of applying an MDP to a real problem. **5. Discount factor, `gamma`.** A number in `[0, 1]` that weights a reward arriving `k` steps from now by `gamma^k`. It expresses how far ahead the agent should care and keeps the total finite when the task never ends. ## The Markov property The M in MDP is the assumption that `P` and `R` depend only on the *current* state and action: ``` P(s_{t+1}, r_{t+1} | s_t, a_t) = P(s_{t+1}, r_{t+1} | s_t, a_t, s_{t-1}, a_{t-1}, ..., s_0) ``` In words: **the current state is a sufficient summary of the past for predicting the future.** This is what lets an algorithm reason about a state without carrying the whole trajectory around. It is a property of your *state representation*, not of the world — if history matters, you fold the relevant history into the state (a delta, a rolling average, the last three readings) and the property is restored. ## What the agent does with it Given an MDP, the agent's behaviour is a **policy**: a rule mapping each state to an action (or to a distribution over actions). The objective is the **expected discounted return** from the current step: ``` G_t = r_{t+1} + gamma*r_{t+2} + gamma^2*r_{t+3} + ... ``` Solving the MDP means finding a policy that maximises `G_t` in expectation. Note the *expectation*: because transitions are stochastic, the same policy produces different trajectories, and the agent optimises the average, not any one run. ## A worked framing A warehouse parcel-sorting robot: - **State**: the robot's aisle position, whether it is carrying a parcel, and which pickup points currently hold parcels. - **Action**: move to an adjacent aisle, pick up, drop at the chute. - **Transition**: mostly deterministic movement, with some probability a pickup fails or a new parcel arrives. - **Reward**: +1 for each parcel delivered to the chute, and a small negative per time step so the robot prefers finishing sooner. - **gamma**: 0.99, so the robot is willing to walk a long way for a parcel. Writing a problem down this way is itself the exercise: if you cannot name the state, the action set and the reward, you do not have an MDP, and no algorithm will rescue you. ## Common confusions - **The transition function is not the reward function.** One says where you go, the other says what you get. - **The reward is not the return.** Reward is one step's feedback; return is the discounted sum over the rest of the trajectory. - **`gamma` is not a learning rate.** It is part of the problem's objective, not a knob on the optimiser. - **Knowing `P` and `R` is not required to *learn* in an MDP.** Many methods learn from sampled experience without ever writing `P` down; the MDP is the model of the problem, not necessarily a model you possess.

  • Which of the five components does the agent control, and which belong to the environment?
    The agent controls only its action choice, through its policy. States, transitions and rewards are produced by the environment; the discount factor is chosen by whoever formulates the problem, so it is a modelling decision rather than something either side controls at run time. That split is why reward design is a specification job, not something the agent can be trusted to fix.
  • Does an MDP require you to know the transition probabilities?
    No. The MDP is the model of the problem; whether you know `P` and `R` decides which methods apply. If you know them you can plan directly against the model. If you do not, the agent learns from sampled transitions instead, which is the usual case in real systems where the dynamics are far too messy to write down.
  • Can an MDP have continuous states and actions?
    Yes. Nothing in the definition requires finiteness — a temperature setpoint or a steering angle is a perfectly good continuous action, and a sensor reading is a continuous state. What changes is the machinery: you can no longer enumerate states in a table, so the value or policy has to be represented by a function that generalises across them.

It is a board game written as rules: the squares are states, the legal moves are actions, the dice give the transitions, the scoring table is the reward, and gamma is your impatience to win soon rather than eventually.

saying these in an interview costs you the question

  • Says the transition function returns the reward
  • Describes the reward as something the agent chooses
  • Claims an MDP requires deterministic transitions
  • Confuses the discount factor with a learning rate
  • Uses reward and return interchangeably
  • Thinks the state must be raw sensor data, never engineered

context

open as a page

What does the discount factor gamma control in a reinforcement learning agent's return?

level: middleimportance: must knowfreq 64%

basics

~20 s

Gamma sets how much a reward arriving k steps later is worth now: it is weighted by gamma^k. Low gamma makes the agent short-sighted, high gamma far-sighted, and gamma below 1 keeps the total finite in a task that never ends.

open as a page

How do you check that a patient's chart is a Markov state for a discharge decision?

level: seniorimportance: should knowfreq 42%

basics

~20 s

Ask whether earlier history would change the action you take. If two patients with identical charts but opposite three-day trends need different decisions, the chart is not a Markov state, so fold trend summaries into it.

open as a page

Why can a reinforcement learning agent maximise its reward and still fail the task?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Because the reward is a proxy for what you want, and the agent optimises the proxy literally. It will find whatever loophole scores highest, so a rising reward curve is evidence the reward is being maximised, not that the task is being done.

open as a page

In reinforcement learning, how do you add intermediate rewards without changing the optimal policy?

level: seniorimportance: nice to knowfreq 32%

basics

~20 s

Use potential-based shaping: add gamma times a potential of the next state minus the potential of the current state. Because these terms cancel along any trajectory, the optimal policy is provably unchanged while the agent still gets useful intermediate signal.

open as a page