Simple Algorithm
Artificial Intelligence · Hidden Layer · 22 min

RL Foundations

Rewards, returns, value functions and exploration.

A gridworld agent stands one step from an exit worth +1+1 and five safe steps from one worth +10+10. Give it the map and value iteration sends it to the +10+10 every time; make it learn from experience and it may never discover the +10+10 at all. This lesson builds the core of reinforcement learning, from returns and value functions through Bellman equations, occupancy measures and sample-based evaluation, to the exploration problem that makes learning harder than planning.

What you’ll learn

  • Formalize the RL problem: the interaction loop, episodic and continuing returns, discounting as a random horizon, and the objective J(π)J(\pi).
  • Define VπV^\pi, QπQ^\pi and the advantage AπA^\pi, derive the Bellman expectation and optimality equations for stochastic policies, and solve policy evaluation as a linear system.
  • Write the return as a linear function of the discounted occupancy measure, derive the flow constraints, and use the resulting linear program to explain deterministic optimal policies and constrained problems.
  • Compare Monte Carlo and bootstrapped evaluation, and model-based and model-free learning, through bias, variance and certainty equivalence.
  • Explain why exploration in MDPs is harder than in bandits, and compute how fast undirected exploration fails on a concrete gridworld.

The reinforcement learning problem

In reinforcement learning an agent interacts with an environment in discrete time. At step tt it observes the state StS_t, picks an action At∼π(⋅∣St)A_t\sim\pi(\cdot\mid S_t) from its policy, and receives a reward Rt+1R_{t+1} and the next state St+1∼P(⋅∣St,At)S_{t+1}\sim P(\cdot\mid S_t,A_t). The model is a finite Markov decision process (S,A,P,r,γ,ρ)(\mathcal S,\mathcal A,P,r,\gamma,\rho), as in Decisions: Utility, MDPs & Bandits, with expected reward r(s,a)=E[Rt+1∣St=s,At=a]r(s,a)=\E[R_{t+1}\mid S_t=s,A_t=a] and start distribution ρ\rho. What makes the problem reinforcement learning rather than planning is that PP and rr are unknown: the agent sees only the transitions it generates.

A policy and the environment together define a distribution over trajectories τ=(S0,A0,R1,S1,A1,… )\tau=(S_0,A_0,R_1,S_1,A_1,\dots),

pπ(τ)=ρ(S0)∏t≥0π(At∣St) P(St+1∣St,At).p_\pi(\tau)=\rho(S_0)\prod_{t\ge0}\pi(A_t\mid S_t)\,P(S_{t+1}\mid S_t,A_t).

Three features separate this from supervised prediction. Feedback is evaluative: a reward, never the correct action. It is often delayed, so credit must be assigned across many steps. And the data are generated by the policy itself, so changing the policy changes what the agent sees next.

Gt=∑k=0∞γkRt+k+1=Rt+1+γ Gt+1,J(π)=ES0∼ρ[Vπ(S0)]=Eπ[∑t≥0γtRt+1]G_t=\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}=R_{t+1}+\gamma\,G_{t+1},\qquad J(\pi)=\E_{S_0\sim\rho}\big[V^\pi(S_0)\big]=\E_\pi\Big[\sum_{t\ge0}\gamma^tR_{t+1}\Big]
The return with discount factor γ∈[0,1)\gamma\in[0,1), and the objective. Episodic tasks fit the same formula: the terminal state is absorbing and pays 0 forever, and then γ=1\gamma=1 is allowed if every policy terminates with probability 1. With rewards in [0,Rmax⁡][0,R_{\max}], 0≤Gt≤Rmax⁡/(1−γ)0\le G_t\le R_{\max}/(1-\gamma); the factor 1/(1−γ)1/(1-\gamma) is the effective horizon.
DerivationDiscounting is a random horizon
  1. ∑t≥01[H>t] Rt+1\sum_{t\ge0}\mathbf 1[H>t]\,R_{t+1}

    Let the episode stop after each step independently with probability 1−γ1-\gamma. Its length HH is geometric, Pr⁡(H>t)=γt\Pr(H>t)=\gamma^t, and independent of everything else. The undiscounted reward collected before the stop is

  2. E[∑t≥01[H>t] Rt+1]=∑t≥0Pr⁡(H>t) E[Rt+1]=∑t≥0γt E[Rt+1]\E\Big[\sum_{t\ge0}\mathbf 1[H>t]\,R_{t+1}\Big]=\sum_{t\ge0}\Pr(H>t)\,\E[R_{t+1}]=\sum_{t\ge0}\gamma^t\,\E[R_{t+1}]

    Take expectations. Independence lets each indicator's expectation factor out (bounded rewards justify exchanging sum and expectation):

  3. E[H]=∑t≥0γt=11−γ\E[H]=\sum_{t\ge0}\gamma^t=\frac{1}{1-\gamma}

    Maximizing the discounted return is therefore the same as maximizing total reward under a constant hazard 1−γ1-\gamma of the episode ending. The expected lifetime is the effective horizon, 100 steps for γ=0.99\gamma=0.99:

Value functions and the Bellman equations

The value function of π\pi is Vπ(s)=Eπ[Gt∣St=s]V^\pi(s)=\E_\pi[G_t\mid S_t=s] and its action-value function is Qπ(s,a)=Eπ[Gt∣St=s,At=a]Q^\pi(s,a)=\E_\pi[G_t\mid S_t=s,A_t=a]. They are linked by Vπ(s)=∑aπ(a∣s) Qπ(s,a)V^\pi(s)=\sum_a\pi(a\mid s)\,Q^\pi(s,a), and their difference is the advantage Aπ(s,a)=Qπ(s,a)−Vπ(s)A^\pi(s,a)=Q^\pi(s,a)-V^\pi(s): how much better aa is than π\pi's average action in ss. By construction ∑aπ(a∣s)Aπ(s,a)=0\sum_a\pi(a\mid s)A^\pi(s,a)=0. Advantages drive policy improvement here and policy gradients in Policy Gradients & Actor–Critic.

DerivationBellman equations for stochastic policies
  1. Qπ(s,a)=r(s,a)+γ∑s′P(s′∣s,a)∑a′π(a′∣s′) Qπ(s′,a′)Q^\pi(s,a)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\sum_{a'}\pi(a'\mid s')\,Q^\pi(s',a')

    Condition the recursion Gt=Rt+1+γGt+1G_t=R_{t+1}+\gamma G_{t+1} on (St,At)=(s,a)(S_t,A_t)=(s,a), then on the next state and action. By the Markov property, the expected return from (St+1,At+1)(S_{t+1},A_{t+1}) onward is Qπ(St+1,At+1)Q^\pi(S_{t+1},A_{t+1}), whatever happened before:

  2. Vπ=rπ+γPπVπ⟹Vπ=(I−γPπ)−1rπ=∑k≥0γk(Pπ)krπV^\pi=r^\pi+\gamma P^\pi V^\pi\quad\Longrightarrow\quad V^\pi=(I-\gamma P^\pi)^{-1}r^\pi=\sum_{k\ge0}\gamma^k\big(P^\pi\big)^kr^\pi

    Average over a∼π(⋅∣s)a\sim\pi(\cdot\mid s). With rπ(s)=∑aπ(a∣s)r(s,a)r^\pi(s)=\sum_a\pi(a\mid s)r(s,a) and Pπ(s,s′)=∑aπ(a∣s)P(s′∣s,a)P^\pi(s,s')=\sum_a\pi(a\mid s)P(s'\mid s,a), a fixed policy turns the MDP into a Markov reward process with a linear value equation:

  3. TπV=rπ+γPπV,(Tπ)kV → k→∞  Vπ  from any VT^\pi V=r^\pi+\gamma P^\pi V,\qquad\big(T^\pi\big)^kV\ \xrightarrow{\ k\to\infty\ }\ V^\pi\ \text{ from any }V

    PπP^\pi is a stochastic matrix, so γPπ\gamma P^\pi has spectral radius at most γ<1\gamma<1 and the Neumann series converges (the argument of Decisions: Utility, MDPs & Bandits). Policy evaluation is one linear solve, O(∣S∣3)\order{|\mathcal S|^3}, or repeated application of the affine map TπT^\pi:

  4. Q∗(s,a)=r(s,a)+γ∑s′P(s′∣s,a)max⁡a′Q∗(s′,a′),π∗(s)∈arg max⁡aQ∗(s,a)Q^*(s,a)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\max_{a'}Q^*(s',a'),\qquad\pi^*(s)\in\argmax_aQ^*(s,a)

    Optimality replaces the average over a′a' by a maximum. Q∗Q^* is the unique fixed point of the Bellman optimality operator TT, and every policy that is greedy for Q∗Q^* is optimal:

Check your understanding

A policy induces this chain: in state AA the agent receives reward 1 and moves to BB; in BB it receives 0 and moves to AA or stays in BB with probability 12\tfrac12 each. With γ=12\gamma=\tfrac12, what is Vπ(A)V^\pi(A)?

  1. 11
  2. 65\tfrac65
  3. 43\tfrac43
  4. 22
Show the answer

B. 65\tfrac65

The Bellman equations are VA=1+12VBV_A=1+\tfrac12V_B and VB=12(12VA+12VB)V_B=\tfrac12\big(\tfrac12V_A+\tfrac12V_B\big). The second gives VB=VA/3V_B=V_A/3, so VA=1+VA/6V_A=1+V_A/6, hence VA=65V_A=\tfrac65 and VB=25V_B=\tfrac25. That is (I−γPπ)−1rπ(I-\gamma P^\pi)^{-1}r^\pi for a 2×22\times2 system.

Predict before you look

At noise 0 the +1+1 exit is one step from the start and the +10+10 exit five steps away; all other rewards are 0. Above what discount factor does the optimal policy cross the bridge?

Show the answer

0.56

Exiting west is worth γ⋅1\gamma\cdot1 and crossing γ5⋅10\gamma^5\cdot10, since an exit's reward counts on the step that enters it. Crossing wins when γ4>110\gamma^4>\tfrac1{10}, that is γ>10−1/4≈0.562\gamma>10^{-1/4}\approx0.562. In the widget at noise 0, γ=0.56\gamma=0.56 still exits west and γ=0.57\gamma=0.57 crosses. A smaller γ\gamma is a shorter effective horizon, over which a distant reward fades below a near one.

Occupancy measures: the linear-programming view

DerivationThe return is linear in d, and d obeys flow constraints
  1. J(π)=∑t≥0γt Eπ[r(St,At)]=∑s,a(∑t≥0γt Pπ(St=s,At=a))r(s,a)=11−γ∑s,adρπ(s,a) r(s,a)J(\pi)=\sum_{t\ge0}\gamma^t\,\E_\pi[r(S_t,A_t)]=\sum_{s,a}\Big(\sum_{t\ge0}\gamma^t\,\mathbb P_\pi(S_t=s,A_t=a)\Big)r(s,a)=\frac{1}{1-\gamma}\sum_{s,a}d^\pi_\rho(s,a)\,r(s,a)

    Expand JJ by linearity and group the terms by the state–action pair visited:

  2. ∑ad(s′,a)=(1−γ)ρ(s′)+γ∑s,aP(s′∣s,a) d(s,a)for every s′\sum_ad(s',a)=(1-\gamma)\rho(s')+\gamma\sum_{s,a}P(s'\mid s,a)\,d(s,a)\qquad\text{for every }s'

    Which dd are possible? The state at t+1t+1 comes from the pair at tt: P(St+1=s′)=∑s,aP(s′∣s,a) P(St=s,At=a)\mathbb P(S_{t+1}=s')=\sum_{s,a}P(s'\mid s,a)\,\mathbb P(S_t=s,A_t=a). Multiply by (1−γ)γt+1(1-\gamma)\gamma^{t+1}, sum over t≥0t\ge0, and add the t=0t=0 term (1−γ)ρ(s′)(1-\gamma)\rho(s'):

  3. max⁡d≥0 11−γ∑s,ad(s,a) r(s,a)subject to the flow constraints\max_{d\ge0}\ \frac{1}{1-\gamma}\sum_{s,a}d(s,a)\,r(s,a)\quad\text{subject to the flow constraints}

    These ∣S∣|\mathcal S| flow constraints, with d≥0d\ge0, say that the discounted mass leaving s′s' equals the mass injected there at the start plus the discounted mass flowing in. Planning is therefore a linear program over a polytope:

Proof sketch. The first claim is the derivation above, which used only that St+1S_{t+1} depends on (St,At)(S_t,A_t). For the converse, let μ(s)=∑ad(s,a)\mu(s)=\sum_ad(s,a), so d(s,a)=μ(s) πd(a∣s)d(s,a)=\mu(s)\,\pi_d(a\mid s) (define πd\pi_d arbitrarily where μ(s)=0\mu(s)=0). The flow constraints become μ⊤=(1−γ)ρ⊤+γμ⊤Pπd\mu^\top=(1-\gamma)\rho^\top+\gamma\mu^\top P^{\pi_d}, whose unique solution μ⊤=(1−γ)ρ⊤(I−γPπd)−1\mu^\top=(1-\gamma)\rho^\top(I-\gamma P^{\pi_d})^{-1} is πd\pi_d's own discounted state distribution. Hence d=dρπdd=d^{\pi_d}_\rho.

Three consequences follow. Deterministic optimal policies exist: a linear objective over a polytope is maximized at a vertex, and the vertices are the occupancy measures of deterministic policies. Values are prices: the dual linear program has one variable per state and constraints V(s)≥r(s,a)+γ∑s′P(s′∣s,a)V(s′)V(s)\ge r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V(s'), the Bellman LP of MDPs: Value & Policy Iteration. Constraints are cheap: a budget ∑s,ad(s,a)c(s,a)≤C\sum_{s,a}d(s,a)c(s,a)\le C on an expected cost keeps the problem a linear program, the constrained MDP (Altman, 1999), but its optimum need not be a vertex. The view also shows why RL data are not i.i.d. for long: dρπd^\pi_\rho moves whenever π\pi does.

Think first In a constrained MDP the best policy can need to randomize, which never happens without constraints. Can you build the smallest example?

One state with a self-loop and two actions: action 1 earns reward 1 at cost 1, action 2 earns 0 at cost 0, and the budget is ∑ad(s,a)c(s,a)≤12\sum_ad(s,a)c(s,a)\le\tfrac12. The flow constraint forces d(s,1)+d(s,2)=1d(s,1)+d(s,2)=1, so the deterministic policies get reward 1 at cost 1 (infeasible) or reward 0 at cost 0. Playing action 1 with probability 12\tfrac12 meets the budget exactly and earns half the maximum. The budget slices the polytope, and the optimum sits on an edge between two vertices. In general a basic optimal solution has at most ∣S∣+k|\mathcal S|+k positive entries for kk constraints, so when every state is visited, some optimal policy randomizes in at most kk states.

Learning from samples: Monte Carlo, bootstrapping, models

Without PP and rr, values must be estimated from experience, and two ideas compete. Monte Carlo (MC) methods average complete observed returns: V(s)V(s) is the sample mean of GtG_t over visits to ss. Bootstrapping methods update a guess toward another guess: temporal-difference learning moves V(St)V(S_t) toward the one-step target Rt+1+γV(St+1)R_{t+1}+\gamma V(S_{t+1}), which is the dynamic-programming backup with a sampled transition in place of the expectation.

text
function MC-EVALUATE(π, episodes):                # first-visit Monte Carlo
    N(s) ← 0;  V(s) ← 0   for every state s
    for each episode S0, A0, R1, ..., ST generated by π:
        G ← 0
        for t = T−1 down to 0:
            G ← R(t+1) + γ · G                    # return from step t
            if S(t) does not occur among S0, ..., S(t−1):
                N(S(t)) ← N(S(t)) + 1
                V(S(t)) ← V(S(t)) + (G − V(S(t))) / N(S(t))
    return V

function TD0-EVALUATE(π, α):                      # bootstraps, updates online
    for each transition (S, A, R, S′) generated by π:
        V(S) ← V(S) + α · (R + γ · V(S′) − V(S))   # V(terminal) = 0

First-visit MC averages i.i.d. returns, so it is unbiased and converges by the law of large numbers, but it must wait for episodes to end. TD(0) updates after every transition and works in continuing tasks; its convergence under Robbins–Monro step sizes is proved in Temporal-Difference Learning & Q-Learning.

MethodModel?Target for V(St)V(S_t)BiasVariance
Dynamic programmingneededr(s,a)+γ∑s′P(s′∣s,a)V(s′)r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V(s'), averaged over π\pinone: an exact expectationnone
Monte Carlonot neededGtG_tnonehigh: the sum of many random rewards and transitions
TD(0)not neededRt+1+γV(St+1)R_{t+1}+\gamma V(S_{t+1})yes, while VV is wronglow: one random transition
nn-step returns and TD(λ\lambda) interpolate between the last two rows.
Check your understanding

Eight episodes are observed, undiscounted: one goes A→BA\to B with rewards 0 then 0; six start in BB and end with reward 1; one starts in BB and ends with reward 0. Batch Monte Carlo and batch TD(0) both estimate V(B)=34V(B)=\tfrac34. What do they estimate for V(A)V(A)?

  1. MC gives 34\tfrac34 and TD gives 00
  2. Both give 34\tfrac34
  3. MC gives 00 and TD gives 34\tfrac34
  4. Both give 00
Show the answer

C. MC gives 00 and TD gives 34\tfrac34

MC averages the returns actually observed from AA: one episode, return 0. Batch TD converges to the values of the maximum-likelihood Markov model of the data, in which AA always moves to BB with reward 0, so V(A)=0+V(B)=34V(A)=0+V(B)=\tfrac34: the certainty-equivalence estimate (Sutton & Barto, Example 6.4). If the process really is Markov, TD's answer is the better one, because it uses the seven other episodes' evidence about BB; MC fits the observed returns and ignores that structure.

The check reveals a third route. A model-based learner counts transitions, P^(s′∣s,a)=N(s,a,s′)/N(s,a)\hat P(s'\mid s,a)=N(s,a,s')/N(s,a), estimates r^\hat r, and plans in the estimated MDP with dynamic programming; batch TD reaches this certainty-equivalence answer without storing the model. Model-based methods extract more from each sample, and Dyna (Sutton, 1990) interleaves real updates with updates on simulated transitions. Their risk is model error, which compounds over the effective horizon: the simulation lemma in Bellman Equations & Contraction bounds every policy's value error by γεRmax⁡/(1−γ)2\gamma\varepsilon R_{\max}/(1-\gamma)^2 when each transition distribution is off by ε\varepsilon in L1L_1. Model-free methods such as Q-learning and policy gradients never model the observations, which is why they scaled to raw pixels first; learned latent models, as in MuZero and Dreamer (World Models & Video Generation), narrow the gap.

Exploration: why learning is harder than planning

A bandit learner must try arms to learn about them, but each try is a single step. In an MDP, information can be many steps away: to learn what the far side of the bridge pays, the agent must first walk across, choosing actions that look worthless by its current estimates. This is the problem of deep exploration, and the exploration strategies of Decisions: Utility, MDPs & Bandits do not solve it on their own.

DerivationHow rare is a lucky crossing?
  1. pi=14 pi+1+14 pi−1,p0=0,p6=1p_i=\tfrac14\,p_{i+1}+\tfrac14\,p_{i-1},\qquad p_0=0,\quad p_6=1

    Take a uniformly random agent at noise 0: the widget at ε=1\varepsilon=1, or any agent before it has seen a reward. Let pip_i be the probability of reaching the +10+10 before any other exit from the cell ii steps east of the +1+1 exit; the start is i=1i=1 and the +10+10 is i=6i=6. Each move goes east or west with probability 14\tfrac14 and falls with probability 12\tfrac12:

  2. pi=sinh⁡(iθ)sinh⁡(6θ),p1=3sinh⁡(6θ)≈1.28×10−3≈1780p_i=\frac{\sinh(i\theta)}{\sinh(6\theta)},\qquad p_1=\frac{\sqrt3}{\sinh(6\theta)}\approx1.28\times10^{-3}\approx\frac{1}{780}

    The characteristic equation x2−4x+1=0x^2-4x+1=0 has roots 2±3=e±θ2\pm\sqrt3=e^{\pm\theta}, where cosh⁡θ=2\cosh\theta=2 and so sinh⁡θ=3\sinh\theta=\sqrt3. The boundary conditions select the sinh solution:

  3. E[episodes until the first crossing]=1p1≈(2+3)n23\E[\text{episodes until the first crossing}]=\frac{1}{p_1}\approx\frac{(2+\sqrt3)^n}{2\sqrt3}

    A random episode crosses about once in 780 tries. With the far exit nn steps from the near one, p1=3/sinh⁡(nθ)≈23 (2+3)−np_1=\sqrt3/\sinh(n\theta)\approx2\sqrt3\,(2+\sqrt3)^{-n}: undirected exploration costs exponentially many episodes in the distance to the reward. An ε\varepsilon-greedy agent that already prefers the +1+1 does worse still, since it leaves the start eastward with probability only ε/4\varepsilon/4.

What works instead is directed exploration. Optimism in the face of uncertainty treats poorly known state–action pairs as if they were excellent, so that the greedy policy travels to them on purpose. R-MAX (Brafman & Tennenholtz, 2002) plans in a model in which every insufficiently tried pair leads to a fictitious state paying the maximum reward, and UCRL2 plans with confidence sets, reaching regret O~(DSAT)\tilde O(DS\sqrt{AT}) in an MDP with diameter DD. Posterior sampling generalizes Thompson sampling: draw an MDP from the posterior and act optimally for it for a whole episode. In deep RL the same ideas return as count-based and pseudo-count bonuses and as curiosity rewards for prediction error.

Key takeaways

  • RL maximizes J(π)=Eπ[∑tγtRt+1]J(\pi)=\E_\pi\big[\sum_t\gamma^tR_{t+1}\big] from sampled interaction, without knowing PP or rr; discounting is equivalent to a random horizon that ends with probability 1−γ1-\gamma per step.
  • VπV^\pi, QπQ^\pi and AπA^\pi satisfy linear Bellman equations, Vπ=(I−γPπ)−1rπV^\pi=(I-\gamma P^\pi)^{-1}r^\pi; optimality replaces the average over actions by a max, and both operators are γ\gamma-contractions.
  • The return is linear in the discounted occupancy measure, which the flow constraints characterize exactly. Planning is a linear program whose vertices are deterministic policies and whose dual variables are values; extra constraints can make randomization necessary.
  • Monte Carlo targets are unbiased but noisy; TD targets bootstrap, trading bias for variance, and batch TD computes the certainty-equivalence estimate of a model-based learner.
  • Undirected exploration can need exponentially many episodes, about 780 for a random walk across a five-cell bridge; optimism and posterior sampling explore on purpose.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For any policy π\pi and state ss, what is ∑aπ(a∣s) Aπ(s,a)\sum_a\pi(a\mid s)\,A^\pi(s,a)?

  1. Vπ(s)V^\pi(s)
  2. 00
  3. max⁡aQπ(s,a)−Vπ(s)\max_aQ^\pi(s,a)-V^\pi(s)
  4. It depends on the rewards
Show the answer

B. 00

∑aπ(a∣s)Qπ(s,a)=Vπ(s)\sum_a\pi(a\mid s)Q^\pi(s,a)=V^\pi(s), so the π\pi-weighted advantages sum to Vπ(s)−Vπ(s)=0V^\pi(s)-V^\pi(s)=0. Some actions are better than the policy's average and some worse, and a policy can be improved exactly where some action has positive advantage.

Question 2

An episode stops after each step with probability 0.020.02, independently of everything else. Maximizing the expected total (undiscounted) reward is equivalent to maximizing the discounted return with which γ\gamma?

  1. 0.020.02
  2. 5050
  3. 0.98500.98^{50}
  4. 0.980.98
Show the answer

D. 0.980.98

Reward Rt+1R_{t+1} is collected only if the episode survives tt steps, which has probability 0.98t0.98^t, so the expected total is ∑t0.98t E[Rt+1]\sum_t0.98^t\,\E[R_{t+1}]: the discounted return with γ=0.98\gamma=0.98, whose effective horizon 1/(1−γ)1/(1-\gamma) is the expected lifetime of 50 steps.

Question 3

Why does the linear-programming view guarantee that some optimal policy is deterministic?

  1. Every occupancy measure puts all its mass on one action per state
  2. The return is linear in the occupancy measure, so it is maximized at a vertex of the occupancy polytope, and vertices are the occupancy measures of deterministic policies
  3. Value iteration only ever outputs deterministic policies
  4. Randomizing always lowers the expected return
Show the answer

B. The return is linear in the occupancy measure, so it is maximized at a vertex of the occupancy polytope, and vertices are the occupancy measures of deterministic policies

The flow constraints and d≥0d\ge0 cut out a polytope, JJ is linear on it, and a linear function attains its maximum at a vertex, which puts mass on one action in each visited state. Add one more linear constraint, as in a constrained MDP, and the optimum can move to an edge between vertices: a randomized policy.

Question 4

Which statement about the Monte Carlo target GtG_t and the TD(0) target Rt+1+γV(St+1)R_{t+1}+\gamma V(S_{t+1}) for estimating Vπ(St)V^\pi(S_t) is correct?

  1. Both are unbiased for any current estimate VV
  2. The TD target is unbiased and GtG_t is biased
  3. GtG_t is unbiased but has higher variance; the TD target has lower variance but is biased while VV is inaccurate
  4. They have the same variance, since both come from the same episode
Show the answer

C. GtG_t is unbiased but has higher variance; the TD target has lower variance but is biased while VV is inaccurate

E[Gt∣St=s]=Vπ(s)\E[G_t\mid S_t=s]=V^\pi(s) by definition, but GtG_t accumulates the randomness of every later step. The TD target has one random transition, and E[Rt+1+γV(St+1)∣St=s]=(TπV)(s)\E[R_{t+1}+\gamma V(S_{t+1})\mid S_t=s]=(T^\pi V)(s), which equals Vπ(s)V^\pi(s) only when the estimate is right on average over the next state.

Question 5

On the noiseless bridge, value iteration finds the crossing policy in a few sweeps, yet ε\varepsilon-greedy Q-learning with ε=0.1\varepsilon=0.1 almost never does. What is the main reason?

  1. A Q-table cannot represent the crossing policy
  2. The +10+10 is reached only through a specific multi-step sequence that the agent's estimates give it no reason to try, and random steps rarely string it together
  3. Q-learning diverges at γ=0.9\gamma=0.9
  4. The learning rate α=0.5\alpha=0.5 is too small
Show the answer

B. The +10+10 is reached only through a specific multi-step sequence that the agent's estimates give it no reason to try, and random steps rarely string it together

After the +1+1 has been found, the greedy action at the start is west, so only an exploratory step leads east, and several more steps must then keep going east without falling. Undirected exploration finds such sequences with probability exponentially small in their length, about 1/7801/780 per episode even for a purely random agent here. Optimism or posterior sampling would send the agent to the untried far side deliberately.

Go deeper

Further reading

  • R. S. Sutton & A. G. Barto, Reinforcement Learning: An Introduction, ch. 3–6 (MIT Press, 2nd ed., 2018).
  • M. L. Puterman, Markov Decision Processes: Discrete Stochastic Dynamic Programming, ch. 6 (Wiley, 1994).
  • C. Szepesvári, Algorithms for Reinforcement Learning (Morgan & Claypool, 2010).
  • E. Altman, Constrained Markov Decision Processes (Chapman & Hall/CRC, 1999).