Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

Average-Reward Dynamic Programming

Gain, bias and relative value iteration for tasks that never end.

A data center, a traffic light and an inventory system never stop, and nothing makes a reward next year worth less than one today. Push γ\gamma toward 1 and discounted values blow up like g/(1−γ)g/(1-\gamma). What survives the limit is the gain gg, the average reward per step, and a finite bias hh that says which states are better places to start. This lesson rebuilds dynamic programming on those two objects.

What you’ll learn

  • Define the gain and bias of a policy, tell unichain from multichain models, and solve the average-reward evaluation equations.
  • Derive the Laurent expansion Vγπ=gπ/(1−γ)+hπ+O(1−γ)V^\pi_\gamma=g^\pi/(1-\gamma)+h^\pi+O(1-\gamma) and use it to explain Blackwell optimality.
  • Prove that the span seminorm contracts under an ergodicity condition, run relative value iteration, and repair periodic chains with the aperiodicity transformation.
  • Bound the optimal gain from any iterate, and connect R-learning and differential Q-learning to these planning methods.

Gain and bias

The two-state world shows all the cases (in s1s_1, stay pays 1, go pays 0 and moves to s2s_2; in s2s_2, stay pays 2, go pays 0 and moves to s1s_1):

  • (go, stay): s1s_1 is transient and s2s_2 absorbing, a unichain policy with g=(2,2)g=(2,2). With P⋆=(0101)P^\star=\begin{pmatrix}0&1\\0&1\end{pmatrix} and Pt=PP^t=P for t≥1t\ge1, only the t=0t=0 term of the bias survives: h=(I−P⋆)r=(−2,0)h=(I-P^\star)r=(-2,0). Starting in s1s_1 costs the 2 you miss on the first step.
  • (stay, stay): two absorbing states, two recurrent classes, g=(1,2)g=(1,2). This policy makes the MDP multichain.
  • (go, go): a deterministic 2-cycle, which is periodic.

The MDP is still communicating, because from each state some policy reaches the other, and in such MDPs the optimal gain is the same everywhere: here g⋆=2g^\star=2.

DerivationProof for an aperiodic unichain policy
  1. (I−P) h=∑t≥0(Pt−Pt+1)r=lim⁡n→∞(I−Pn+1)r=r−P⋆r=r−g(I-P)\,h=\sum_{t\ge0}\big(P^t-P^{t+1}\big)r=\lim_{n\to\infty}\big(I-P^{n+1}\big)r=r-P^\star r=r-g

    Pt→P⋆P^t\to P^\star geometrically fast for a finite aperiodic chain, so the bias series converges. Apply I−PI-P term by term; since (I−P)P⋆=0(I-P)P^\star=0, each term is (Pt−Pt+1)r(P^t-P^{t+1})r, and the sum telescopes:

  2. g=μr,h unique up to c1g=\mu r,\qquad h\ \text{unique up to }c\mathbf 1

    That is h+g=r+Phh+g=r+Ph with g=P⋆r=g1g=P^\star r=g\mathbf 1. Multiplying any solution by μ\mu (which satisfies μP=μ\mu P=\mu) gives μh+g=μr+μh\mu h+g=\mu r+\mu h, so g=μrg=\mu r is forced. Two solutions for hh differ by a vector xx with Px=xPx=x, and in a chain with one recurrent class such xx are constant:

The Laurent series and Blackwell optimality

DerivationProof sketch (aperiodic case)
  1. Vγ=∑t≥0γtPtr=∑t≥0γtP⋆r+∑t≥0γt(Pt−P⋆)r=g1−γ+∑t≥0γt(Pt−P⋆)rV_\gamma=\sum_{t\ge0}\gamma^tP^tr=\sum_{t\ge0}\gamma^tP^\star r+\sum_{t\ge0}\gamma^t\big(P^t-P^\star\big)r=\frac{g}{1-\gamma}+\sum_{t\ge0}\gamma^t\big(P^t-P^\star\big)r

    Split each PtP^t into its limit and the rest, using PtP⋆=P⋆P^tP^\star=P^\star:

  2. ∥∑t≥0(1−γt)(Pt−P⋆)r∥∞≤(1−γ)∑t≥0t ∥Pt−P⋆∥∞∥r∥∞=O(1−γ)\Big\|\sum_{t\ge0}(1-\gamma^t)\big(P^t-P^\star\big)r\Big\|_\infty\le(1-\gamma)\sum_{t\ge0}t\,\big\|P^t-P^\star\big\|_\infty\norm{r}_\infty=O(1-\gamma)

    The last sum tends to hh. Its distance from hh is ∑t(1−γt)(Pt−P⋆)r\sum_t(1-\gamma^t)(P^t-P^\star)r, and 1−γt≤t(1−γ)1-\gamma^t\le t(1-\gamma) while ∥Pt−P⋆∥∞\norm{P^t-P^\star}_\infty decays geometrically, so the remainder is O(1−γ)O(1-\gamma). For periodic chains the same statement holds with Cesàro limits (Puterman, 1994, ch. 8).

Two exact examples. Under (go, stay), Vγ=(2γ/(1−γ), 2/(1−γ))=21−γ1+(−2,0)V_\gamma=\big(2\gamma/(1-\gamma),\ 2/(1-\gamma)\big)=\frac{2}{1-\gamma}\mathbf 1+(-2,0), with no remainder at all. For a deterministic 2-cycle that pays 2 and then 0, Vγ=11−γ1+11+γ(1,−1)V_\gamma=\frac{1}{1-\gamma}\mathbf 1+\frac{1}{1+\gamma}(1,-1): gain 1, bias (12,−12)(\tfrac12,-\tfrac12), and a remainder 11+γ−12=O(1−γ)\frac{1}{1+\gamma}-\frac12=O(1-\gamma).

Since every policy's values are dominated by g/(1−γ)g/(1-\gamma) as γ→1\gamma\to1, a policy that is optimal for all γ\gamma close to 1 must maximize the gain first and then the bias. Blackwell proved that such a policy exists.

Predict before you look

Option A pays 1 at every step forever. Option B pays 0 for the first 10 steps, then 1.1 at every step forever. B has the higher gain. Above which discount factor does a discounted planner also prefer B?

Show the answer

0.99

A is worth 11−γ\frac{1}{1-\gamma} and B is worth 1.1γ101−γ\frac{1.1\gamma^{10}}{1-\gamma}, so B wins when γ10>1/1.1\gamma^{10}>1/1.1, that is γ>1.1−1/10≈0.9905\gamma>1.1^{-1/10}\approx0.9905. With a 100-step delay the threshold moves to about 0.99905. The Blackwell threshold can sit arbitrarily close to 1, so a fixed γ\gamma such as 0.99 is no guarantee of gain-optimal behavior.

Relative value iteration

In a unichain MDP, and more generally in a weakly communicating one such as the two-state world, the optimal gain g⋆g^\star is the same in every state, and with an optimal bias h⋆h^\star it solves the optimality equation

h⋆(s)+g⋆=max⁡a[r(s,a)+∑s′P(s′∣s,a) h⋆(s′)],h^\star(s)+g^\star=\max_a\Big[r(s,a)+\sum_{s'}P(s'\mid s,a)\,h^\star(s')\Big],

and any policy attaining the maximum is gain-optimal. In the two-state world, g⋆=2g^\star=2 and h⋆=(−2,0)h^\star=(-2,0) solve it (normalized at s2s_2), and the maximizing policy is (go, stay). Multichain models with a state-dependent optimal gain need a nested pair of equations (Puterman, 1994, ch. 9).

Undiscounted value iteration vk+1=Tvkv_{k+1}=\mathcal Tv_k, with Tv(s)=max⁡a[r(s,a)+∑s′P(s′∣s,a)v(s′)]\mathcal Tv(s)=\max_a[r(s,a)+\sum_{s'}P(s'\mid s,a)v(s')], grows like kg⋆kg^\star. Relative value iteration (White, 1963) subtracts the value at a reference state after every step, which keeps the iterates bounded:

hk+1=Thk−(Thk)(sref) 1,gk+1=(Thk)(sref).h_{k+1}=\mathcal Th_k-(\mathcal Th_k)(s_{\text{ref}})\,\mathbf 1,\qquad g_{k+1}=(\mathcal Th_k)(s_{\text{ref}}).

Subtracting constants never changes a greedy action, so RVI computes the same policies as undiscounted value iteration.

DerivationProof of the span contraction
  1. (p−q)⋅x≤(1−∑jmin⁡(pj,qj))(max⁡x−min⁡x)(p-q)\cdot x\le\Big(1-\sum_j\min(p_j,q_j)\Big)\big(\max x-\min x\big)

    Two rows. For probability vectors p,qp,q let d=p−qd=p-q. Its positive and negative parts each have mass 1−∑jmin⁡(pj,qj)1-\sum_j\min(p_j,q_j), because dd sums to zero. So for any vector xx:

  2. (Tv−Tu)(s)≤P(⋅∣s,as)⋅x,(Tv−Tu)(s′)≥P(⋅∣s′,bs′)⋅x(\mathcal Tv-\mathcal Tu)(s)\le P(\cdot\mid s,a_s)\cdot x,\qquad(\mathcal Tv-\mathcal Tu)(s')\ge P(\cdot\mid s',b_{s'})\cdot x

    The max operator. Let asa_s be greedy for vv at ss and bs′b_{s'} greedy for uu at s′s'. Bounding each maximum by the action that attains the other gives, with x=v−ux=v-u:

  3. sp⁡(Tv−Tu)=max⁡s,s′[(Tv−Tu)(s)−(Tv−Tu)(s′)]≤δˉ sp⁡(v−u)\operatorname{sp}(\mathcal Tv-\mathcal Tu)=\max_{s,s'}\big[(\mathcal Tv-\mathcal Tu)(s)-(\mathcal Tv-\mathcal Tu)(s')\big]\le\bar\delta\,\operatorname{sp}(v-u)

    Subtract and apply the two-row bound to the rows of (s,as)(s,a_s) and (s′,bs′)(s',b_{s'}). Taking the maximum over s,s′s,s' gives the contraction. RVI's iterates differ from undiscounted value iteration's only by constants, which the span ignores, so they converge in span to h⋆h^\star, and since hk(sref)=0h_k(s_{\text{ref}})=0 for k≥1k\ge1, gk+1=(Thk−hk)(sref)→g⋆g_{k+1}=(\mathcal Th_k-h_k)(s_{\text{ref}})\to g^\star.

Periodicity breaks it. On the 2-cycle that pays 2 and then 0, the two rows of PP share no state, so δˉ=1\bar\delta=1. From h0=0h_0=0 with reference s2s_2, RVI produces h1=(2,0)h_1=(2,0) and gain estimate 0, then h2=(0,0)h_2=(0,0) and estimate 2, then (2,0)(2,0) and 0 again: it oscillates forever around the true gain 1.

The aperiodicity transformation repairs this. Replace PP by P~=(1−τ)I+τP\tilde P=(1-\tau)I+\tau P and rr by r~=τr\tilde r=\tau r for some τ∈(0,1)\tau\in(0,1). If h+g=r+Phh+g=r+Ph, then r~+P~h=h+τg\tilde r+\tilde Ph=h+\tau g, so the bias is unchanged, every gain is multiplied by τ\tau, and the gain-optimal policies are the same. Every state now has a self-loop, so no chain is periodic. With τ=12\tau=\tfrac12 the 2-cycle's rows both become (12,12)(\tfrac12,\tfrac12), δˉ=0\bar\delta=0, and RVI settles at once: h=(1,0)h=(1,0) (normalized at s2s_2) after the first step, and the gain estimate g~=12\tilde g=\tfrac12 from the second, so g=1g=1.

Check your understanding

On the 2-cycle that pays 2 and then 0, RVI's gain estimates alternate 0, 2, 0, 2, … What is the correct diagnosis?

  1. The chain is periodic, so the span does not contract; adding self-loops with the aperiodicity transformation fixes it
  2. The reference state was badly chosen; using s1s_1 instead would converge
  3. The MDP is multichain, so the gain is not constant
  4. RVI needs a discount factor below 1 to converge
Show the answer

A. The chain is periodic, so the span does not contract; adding self-loops with the aperiodicity transformation fixes it

The two rows of PP, (0,1)(0,1) and (1,0)(1,0), share no state, so δˉ=1\bar\delta=1 and nothing forces the iterates together. Replacing PP by 12(I+P)\tfrac12(I+P) and rr by 12r\tfrac12r keeps the bias and halves the gain, and RVI then converges at once to g~=12\tilde g=\tfrac12, so g=1g=1.

From planning to learning

Replacing the expectation in RVI by a sampled transition gives average-reward TD methods. R-learning (Schwartz, 1993) learns action values R(s,a)R(s,a) together with an estimate ρ\rho of the gain, updating ρ\rho on greedy steps. RVI Q-learning (Abounadi, Bertsekas & Borkar, 2001) subtracts a reference quantity such as Q(sref,aref)Q(s_{\text{ref}},a_{\text{ref}}), mirroring RVI, and comes with a convergence proof. Differential Q-learning (Wan, Naik & Sutton, 2021) removes the reference state: it updates the gain estimate with the TD error itself, and is proven convergent in the tabular case, off-policy.

python
def differential_q_step(Q, r_bar, s, a, reward, s_next, alpha=0.1, eta=1.0):
    """One update of differential Q-learning (Wan, Naik & Sutton, 2021).
    Q: S x A array of differential action values; r_bar: average-reward estimate."""
    delta = reward - r_bar + Q[s_next].max() - Q[s, a]   # no discount anywhere
    Q[s, a] += alpha * delta
    r_bar += eta * alpha * delta                          # the gain moves with the TD error
    return r_bar

Compare with RVI: rˉ\bar r plays the role of gg, and the TD error is a sampled version of (TQ−Q)(s,a)−rˉ\big(\mathcal TQ-Q\big)(s,a)-\bar r. Average-reward forms of the policy gradient theorem appear in The Policy Gradient Theorem in Depth.

Key takeaways

  • The gain g=P⋆rg=P^\star r is the long-run reward per step and the bias h=∑t(Pt−P⋆)rh=\sum_t(P^t-P^\star)r the total excess over it. For unichain policies they solve h+g1=r+Phh+g\mathbf 1=r+Ph, with gg unique and hh unique up to a constant.
  • Vγπ=gπ/(1−γ)+hπ+O(1−γ)V^\pi_\gamma=g^\pi/(1-\gamma)+h^\pi+O(1-\gamma): discounting for γ\gamma near 1 ranks policies by gain, then bias. A Blackwell-optimal policy exists, but its threshold γ0\gamma_0 can be arbitrarily close to 1.
  • Relative value iteration subtracts a reference value each step. It converges geometrically when the span contracts, δˉ<1\bar\delta<1; periodic chains need the aperiodicity transformation, which keeps the bias and scales the gain.
  • For any iterate, min⁡(Th−h)≤gπ≤g⋆≤max⁡(Th−h)\min(\mathcal Th-h)\le g^\pi\le g^\star\le\max(\mathcal Th-h), which gives a stopping rule; R-learning, RVI Q-learning and differential Q-learning are the sampled versions.

Check yourself

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

Question 1

In the two-state world, the policy (stay, stay) keeps each state absorbing, with rewards 1 and 2. Which description is right?

  1. Unichain, with gain 1.5 everywhere
  2. Multichain, with gain 1 in s1s_1 and 2 in s2s_2
  3. Periodic, with gain 1.5
  4. Unichain, with gain 2, because s2s_2 is the better state
Show the answer

B. Multichain, with gain 1 in s1s_1 and 2 in s2s_2

Each absorbing state is its own recurrent class, so the chain has two classes and the gain depends on where you start: g=P⋆r=(1,2)g=P^\star r=(1,2). One such policy is enough to make the MDP multichain.

Question 2

A unichain policy has gain 1.5 and bias h(s)=−3h(s)=-3 at state ss. About how large is its discounted value at ss for γ=0.99\gamma=0.99?

  1. 150
  2. 153
  3. 1.5
  4. 147
Show the answer

D. 147

Vγ(s)=g1−γ+h(s)+O(1−γ)=150−3+O(0.01)≈147V_\gamma(s)=\frac{g}{1-\gamma}+h(s)+O(1-\gamma)=150-3+O(0.01)\approx147. The gain sets the scale and the bias the offset between states.

Question 3

During relative value iteration in a unichain MDP, (Thk)(s)−hk(s)(\mathcal Th_k)(s)-h_k(s) ranges from 1.9 to 2.1 across states. What can you conclude?

  1. g⋆=2g^\star=2 exactly
  2. 1.9≤g⋆≤2.11.9\le g^\star\le2.1, and a policy greedy for hkh_k has gain at least 1.9
  3. Nothing until the span reaches 0
  4. g⋆≥2.1g^\star\ge2.1, since value iteration underestimates
Show the answer

B. 1.9≤g⋆≤2.11.9\le g^\star\le2.1, and a policy greedy for hkh_k has gain at least 1.9

For any hh, the minimum and maximum of Th−h\mathcal Th-h bracket both the optimal gain and the gain of a greedy policy. The width of the bracket, the span, is the stopping criterion.

Question 4

Which statement about a Blackwell-optimal policy is true?

  1. It is optimal for every discount factor γ∈[0,1)\gamma\in[0,1)
  2. It maximizes the bias among all policies
  3. It is optimal for all γ\gamma in some interval [γ0,1)[\gamma_0,1), is gain-optimal, and has the largest bias among gain-optimal policies
  4. It exists only in unichain MDPs
Show the answer

C. It is optimal for all γ\gamma in some interval [γ0,1)[\gamma_0,1), is gain-optimal, and has the largest bias among gain-optimal policies

Blackwell's theorem gives a single deterministic policy that is optimal for all γ\gamma near 1, and the Laurent expansion forces it to maximize the gain first and then the bias. In the two-state world, (go, stay) is Blackwell-optimal with γ0=0.5\gamma_0=0.5; below 0.5, stay is better in s1s_1.

Further reading

  • M. L. Puterman, Markov Decision Processes: Discrete Stochastic Dynamic Programming, ch. 8–9 (Wiley, 1994).
  • D. Blackwell, "Discrete dynamic programming," Annals of Mathematical Statistics 33(2), 719–726 (1962).
  • A. Schwartz, "A reinforcement learning method for maximizing undiscounted rewards," ICML (1993).
  • J. Abounadi, D. P. Bertsekas & V. S. Borkar, "Learning algorithms for Markov decision processes with average cost," SIAM Journal on Control and Optimization 40(3), 681–698 (2001).
  • Y. Wan, A. Naik & R. S. Sutton, "Learning and planning in average-reward Markov decision processes," ICML (2021).