skip to content

Planning and Learning

How a policy actually gets better: planning by value iteration when the model is known, Monte-Carlo and TD learning when it is not, then Q-learning, SARSA, policy gradients and when to skip RL.

on this pageshow

explore

questions

20

Value iteration needs a known model — what exactly must that model give you?

level: juniorimportance: must knowfreq 50%

answer

  1. dynamics, not a dataset
  2. probability of every successor state
  3. expected reward per transition
  4. the update is an expectation
  5. planning inside a model

basics

~20 s

For every state and action, the model must give the probability of each possible next state and the expected reward. Value iteration averages over all successors in every update, so it plans inside the model rather than learning from experience.

solid answer

~40 s

Value iteration is a planning method: it needs the MDP's dynamics written down. Concretely, for each state `s` and action `a` you need `P(s'|s,a)` for every successor `s'`, plus the expected reward of that transition. Every update is a full-width backup, `v(s) <- max_a sum_s' P(s'|s,a) * [r(s,a,s') + gamma * v(s')]`, which sums over the whole successor distribution rather than over anything that happened. That is why a restocking problem is a natural fit: if demand follows a known distribution and your ordering rules are fixed, you can enumerate every next inventory level and its probability, so you can solve for the optimal ordering policy before ever touching the warehouse. Without those numbers there is nothing to sum over, and a different family of methods is needed.

go deeper

for a junior

Be ready to say that value iteration needs the transition probabilities and expected rewards for every state and action, and that this is why it is called planning rather than learning.

for a middle

Explain the full-width backup out loud: for each action you sum over every successor weighted by its probability, then take the best action. Say why no distribution means no expectation to compute.

for a senior

Show where a usable model comes from in a real problem, such as a fitted demand or failure distribution, and note that a sweep costs roughly the number of states times actions times successors, which bounds what you can solve exactly.

for a principal

Own the framing decision: whether a problem should be posed as a planning problem with a written-down model at all, what it costs the organisation to build and maintain that model, and what is gained over simpler decision rules.

## What "a model" means here A Markov decision process is the tuple: a set of states `S`, a set of actions `A`, transition dynamics `P(s'|s,a)`, a reward function, and a discount factor `gamma`. The **model** is the pair that describes the environment's behaviour: the transition probabilities and the rewards. Knowing the model means that, sitting at your desk with no environment running, you can answer the question *"if I am in state `s` and take action `a`, what is the full probability distribution over where I end up, and what reward do I expect?"* That is a stronger requirement than it first sounds. It is not enough to know one likely outcome; you need the whole distribution, because the algorithm's arithmetic is an expectation over it. ## Why value iteration cannot run without it One value-iteration update of a single state is ``` v_new(s) = max over a of sum over s' of P(s'|s,a) * [ r(s,a,s') + gamma * v_old(s') ] ``` Read that literally. To compute the value of one action you must enumerate every successor state, weight it by its probability, add the reward you expect on the way, and add the discounted value you already hold for that successor. This is called a **full-width backup**: it touches all branches of the one-step tree, not a sampled branch. Then you take the maximum over actions, because you get to choose. If you do not have `P`, there is no distribution to sum over and no expectation to take. This is the precise sense in which value iteration is *planning*: all of the computation happens inside a model you already possess, and the environment is never touched. Nothing is estimated from interaction; the only thing being computed is the consequence of arithmetic you could in principle do by hand. ## Where a known model actually comes from Candidates sometimes treat "known model" as a fantasy. In practice it is common: - **Operations problems built on a fitted demand or arrival distribution.** An inventory-restocking MDP whose state is stock on hand and whose demand each period follows a known distribution has fully enumerable dynamics: for each order quantity you can compute the probability of each next stock level. - **Engineered systems with reliability data.** A machine that fails with a tabulated probability per period gives you `P` directly. - **Rule-governed systems.** Board games, scheduling problems, and routing on a known network have dynamics that are simply the rules. In each case the model may itself be estimated from data, but once it is written down it is *treated as known* and the planning step is exact arithmetic against it. ## Consequences worth knowing **The state space must be enumerable.** A sweep touches every state, and each state's update touches every action and every successor. For a dense model that is on the order of `|S| * |A| * |S|` operations per sweep. If states are counted in the billions, exact sweeps are out even with a perfect model. **Initial values do not matter much.** You typically start `v(s) = 0` everywhere. The updates contract towards the optimal values regardless of the starting guess (terminal states are pinned at zero). **Optimality is relative to the model.** Value iteration returns the exactly optimal policy for the numbers you fed it. If `P` is wrong, the policy is optimal for a world that does not exist — an important caveat whenever the model came from estimates. **Asynchronous updates are allowed.** The classic sweep updates every state from the previous iteration's values, but you may update states in any order, in place, as long as every state keeps being revisited. This is often much faster in practice and does not change what the method needs to know. ## The short version to say out loud "I need `P(s'|s,a)` and the expected reward for every state–action pair, because each update is an expectation over the entire successor distribution. That is what makes it planning rather than learning — the environment is never queried; I am doing arithmetic inside a model I already have."

  • Where do the transition probabilities in a planning problem usually come from?
    From the structure of the problem rather than from trial and error: a fitted demand distribution in an inventory problem, failure rates from reliability tables for a maintenance problem, the published rules of a game, or a physical or queueing model. They are often estimated from historical records once and then treated as fixed inputs to the planner.
  • Does value iteration have to update states in a fixed order?
    No. The textbook sweep is synchronous — every state is updated from the previous iteration's values — but asynchronous variants update states one at a time, in place, in any order. They still converge to the same optimal values provided every state continues to be updated, and choosing a good order often converges much faster.
  • What limits how large a problem you can plan over exactly?
    The state space, because each sweep touches every state and every state's update touches every action and successor. Roughly `|S| * |A| * |S|` operations per sweep for dense dynamics. Beyond a few million states you need aggregation, structure in the model, or restricting attention to states reachable from the start.

It is the difference between reading the full rulebook of a board game and working out the best move at the table, versus having only a pile of scoresheets from games other people played.

saying these in an interview costs you the question

  • Says value iteration learns the policy from collected episodes
  • Thinks knowing only the reward function is enough
  • Treats the model as one next state instead of a distribution
  • Assumes the model must be exactly true rather than assumed known

context

open as a page

Why do policy gradient methods suit continuous action spaces better than value-based control?

level: juniorimportance: must knowfreq 66%

basics

~20 s

Policy gradient methods tune the policy's parameters directly, so an action is sampled from a distribution. Value-based control has to maximise a value estimate over all actions at every step, which is intractable when the action is a real-valued vector.

open as a page

How does policy iteration alternate evaluation and improvement to reach an optimal policy?

level: middleimportance: must knowfreq 65%

basics

~20 s

Policy iteration repeats two steps. Evaluation sweeps every state, replacing its value with the expected return of the current policy. Improvement then rebuilds the policy greedily from those values; when no action changes, the policy is optimal.

open as a page

How does REINFORCE turn sampled episode returns into a gradient on the policy's parameters?

level: middleimportance: must knowfreq 72%

basics

~20 s

REINFORCE weights the gradient of each action's log-probability by the return that followed it: theta <- theta + lr * G_t * grad log pi(a_t | s_t). Actions from high-return episodes get more probable. The reward itself is never differentiated.

open as a page

How do the Q-learning and SARSA update rules differ, and which one is off-policy?

level: middleimportance: must knowfreq 65%

basics

~20 s

Q-learning's target uses the maximum action value in the next state, so it learns the greedy policy while behaving some other way, which makes it off-policy. SARSA's target uses the action actually taken next, so it evaluates the exploring policy itself: on-policy.

open as a page

How does the one-step TD(0) update revise a state-value estimate?

level: middleimportance: must knowfreq 74%

basics

~20 s

After one transition, TD(0) moves the estimate a fraction of the way toward the observed reward plus the discounted estimate of the next state: V(s) <- V(s) + alpha * [r + gamma * V(s') - V(s)]. The bracketed quantity is the TD error.

open as a page

When does a delayed payoff justify reinforcement learning over supervised next-step prediction?

level: middleimportance: must knowfreq 58%

basics

~20 s

Reinforcement learning earns its cost when the only outcome you can measure arrives after a long sequence of decisions, so no per-decision target exists. If you can write an honest label for each decision, supervised learning is cheaper and safer.

open as a page

What separates model-free from model-based reinforcement learning?

level: juniorimportance: should knowfreq 62%

basics

~20 s

A model-based agent has (or learns) the environment's transition and reward dynamics and can plan against them. A model-free agent never builds those dynamics; it estimates values or a policy directly from sampled experience. Temporal-difference learning is model-free.

open as a page

What is the difference between value iteration and policy iteration on the same MDP?

level: middleimportance: should knowfreq 58%

basics

~20 s

Policy iteration evaluates the current policy to convergence, then makes it greedy, repeats. Value iteration folds both into one sweep that takes the maximum over actions. Both reach the same optimal values, trading cost per round against number of rounds.

open as a page

In REINFORCE, why does subtracting a baseline from the return cut gradient variance?

level: middleimportance: should knowfreq 57%

basics

~10 s

Weighting by return minus a baseline centres the weights, so better-than-average actions are pushed up and worse-than-average ones down, instead of everything rising. Any baseline independent of the chosen action leaves the gradient unbiased.

open as a page

Why is a Monte-Carlo return unbiased while a one-step TD target is biased?

level: middleimportance: should knowfreq 55%

basics

~20 s

A first-visit Monte-Carlo return is an actual sampled return, so on average it equals the true value — unbiased, but noisy because it accumulates every random reward to the end of the episode. A TD target uses the current estimate of the next state, which is wrong early on, so it is biased but far lower variance.

open as a page

In reinforcement learning, why does the cost of one environment interaction decide feasibility?

level: middleimportance: should knowfreq 50%

basics

~20 s

Trial-and-error learning needs enormous numbers of episodes, so reinforcement learning is feasible only where one episode is cheap, fast and safe. A simulator can yield a million overnight; an agent whose episode is a fiscal quarter yields four a year.

open as a page

Why can acting greedily with respect to a policy's value function never make it worse?

level: seniorimportance: should knowfreq 34%

basics

~20 s

In every state the greedy action is worth at least as much as the current policy's action, and that advantage applies again at the next step. Unrolling it shows the greedy policy's return dominates everywhere — the policy improvement theorem.

open as a page

Why must a REINFORCE run discard its collected trajectories after a single gradient update?

level: seniorimportance: should knowfreq 43%

basics

~20 s

The policy gradient is an expectation over trajectories drawn from the current policy. One update moves the policy, so the batch now comes from a different distribution and estimates the wrong expectation. Every step needs fresh interaction.

open as a page

Why does SARSA learn a safe inland route while Q-learning hugs the cliff edge under the same epsilon-greedy exploration?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Q-learning bootstraps from the greedy next action, so its values describe an agent that never steps off the cliff, and the short edge path looks best. SARSA bootstraps from the exploratory action actually taken, so occasional random falls depress the edge cells' values.

open as a page

In offline RL on logged ICU sepsis dosing records, what makes the learned policy untrustworthy?

level: seniorimportance: should knowfreq 36%

basics

~20 s

Trained only on logged decisions, an offline policy extrapolates the value of doses clinicians rarely gave, and maximisation selects exactly those over-optimistic estimates. You also cannot test it without acting, and the unrecorded reasons behind each dose confound the data.

open as a page

Value iteration planned an optimal policy from estimated transition probabilities — what can go wrong?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

The policy is exactly optimal for the model you supplied, not for the world. Errors in the transition probabilities compound over the discounted horizon, and the planner actively exploits any transition whose probability or reward was estimated too optimistically.

open as a page

How do you choose n in n-step TD returns when the reward arrives far in the future?

level: seniorimportance: nice to knowfreq 28%

basics

~20 s

Pick n on the delay between action and reward. Small n gives low-variance but myopic targets that propagate credit one state per pass; large n propagates credit fast but carries the noise of a long trajectory. Tune n empirically; intermediate values usually beat both extremes.

open as a page

In tabular Q-learning, when would you prefer a constant learning rate over a decaying one?

level: principalimportance: nice to knowfreq 30%

basics

~20 s

Prefer a constant learning rate when the environment drifts, because it keeps weighting recent experience and lets the agent track change. Prefer a decaying one when the problem is stationary and you want the convergence guarantee, which a constant rate forfeits.

open as a page

When is building a simulator to train an RL agent worth the investment, and when is it a trap?

level: principalimportance: nice to knowfreq 26%

basics

~20 s

Build a simulator when the dynamics are well understood and the real system is too slow or unsafe to explore. It is a trap when the hardest part to model is the part that matters: the agent optimises your assumptions.

open as a page