Approximate Solution Methods/Average-Reward Control for Continuing Tasks

Lesson 3.42,346 words

Average-Reward Control for Continuing Tasks

With function approximation, discounting has no effect on a continuing task: averaged over the on-policy distribution, the discounted objective equals the average reward times a policy-independent constant, so γ\gamma cannot change which policy is best. This lesson replaces discounting with the average-reward setting — the long-run reward rate r(π)r(\pi), the differential return that measures each state's transient advantage over that rate, differential value functions and TD error, and differential semi-gradient Sarsa, the control method for continuing tasks that never invokes a discount factor.

╌╌╌╌

This builds on on-policy control with approximation, which carried the semi-gradient update over to action values and solved Mountain Car — an episodic, discounted task. That lesson ended on a warning: once the state space is too large to enumerate, discounting the future starts to come apart. This lesson makes that precise and supplies the replacement, the average-reward formulation of continuing control.

Average reward: a new problem setting

So far everything has been episodic and discounted. There is a third classical setting for the goal of an MDP, standing alongside them: the average-reward setting, which applies to continuing problems — interaction that goes on forever with no terminal state and no restarts. Unlike the discounted case there is no discounting; the agent cares just as much about delayed reward as immediate reward. This setting is central to the classical theory of dynamic programming and less common in reinforcement learning, but with function approximation it becomes necessary — for reasons the next section makes precise.1

The idea in one line: instead of the total reward collected from a state (which needs discounting to stay finite), the objective is the rate of reward the policy sustains forever, and states are measured by how much better or worse than that rate they start out.

The three problem settings for an MDP's objective. Episodic tasks sum undiscounted reward to a terminal state; discounted continuing tasks weight future reward by ; average-reward continuing tasks maximize the long-run reward rate with no discounting. Function approximation pushes continuing control from the middle column to the right.

The quality of a policy is its long-run average reward per step, denoted :

where the expectations are conditioned on the start state and on actions following thereafter. Here is the steady-state distribution, , assumed to exist for any and to be independent of the start state. That independence is the assumption of ergodicity: where the MDP starts, and any early decision, has only a temporary effect; in the long run the probability of being in a state depends only on the policy and the transition dynamics.

The steady-state distribution is the special distribution under which, if you select actions according to , you stay in the same distribution:

Selecting an action under from a state drawn from leaves the next-state distribution equal to again — the distribution is stationary under the policy, and that stationarity is what makes the average rate of reward well defined.

Ergodicity and the steady-state distribution. Starting from any of several initial states (left), the state distribution under a fixed policy mixes over time and converges to the same steady-state (right), independent of where it started. This mixing is what makes the average reward well defined.

Why discounting fails with approximation

Why abandon the discounted setting we have used all along? Because with function approximation it stops carrying information. Consider a continuing problem with no beginning or end and no clearly identified states — states represented only by feature vectors that may do little to distinguish one from another. In the extreme, imagine all the feature vectors are the same, so every state looks identical to the approximator. Then the only thing the problem can be judged on is the reward sequence, and performance must be assessed purely from that.

Now try to use discounting. At each step you could measure the discounted return; some returns are big and some small, so you would average them over a long interval — which is just the average-reward idea again. The decisive fact is what that average equals. For any policy , the average of the discounted returns is proportional to the average reward:

The discount rate enters only through the constant factor , which is the same for every policy. So it cancels out of any comparison: the ordering of all policies under the discounted objective is identical to their ordering under the undiscounted average-reward objective. The discount rate has no effect on which policy is best — it could be set to zero and the ranking would be unchanged.

The futility-of-discounting argument. Averaging the discounted return over the on-policy distribution yields , so the factor is a policy-independent constant: two policies keep the same relative order whatever is, and carries no information about which policy is better.

Two arguments make this equality solid. The first is a symmetry count. Every time step is identical to every other, so with discounting each reward appears once in each position across the family of returns: the reward at step shows up undiscounted in the return that begins at , discounted once in the return that begins at , discounted times in the return that begins steps earlier. Its total weight across all returns is . Since every reward carries that same weight, the average of the discounted returns is times the average reward, .

The second is a direct derivation that pins it exactly: the same fact follows from the Bellman equation in four lines. Define the objective as the discounted value averaged over the on-policy distribution, , with the ordinary discounted value function. Expand by its Bellman equation and use the steady-state property of :

The first reward term collapsed to because is precisely the definition of average reward; the inner double sum over in the second term collapsed to because is stationary under . Unrolling gives . The discount appears only in that policy-independent constant, so it cannot change which policy maximizes .

The general version of this argument shows that optimizing discounted value over the on-policy distribution is identical to optimizing undiscounted average reward — the value of has no effect. So discounting has no role to play in the definition of the control problem with function approximation. One can still use inside a solution method, turning it from a problem parameter into an algorithm parameter, but there is a deeper loss behind this.

The root cause of the difficulty is the policy improvement theorem. In the tabular case, improving the discounted value of one state is guaranteed to improve the overall policy; with function approximation, that guarantee is gone. Changing the weights to raise at one state can lower it at others, because the states share parameters — so a greedy step is no longer certain to help. Without the improvement theorem the discounted control setting loses the property that justified it, and the average-reward setting is the natural replacement.

Differential returns and value functions

If there is no discounting, what plays the role of the return? In the average-reward setting the return is defined in terms of differences between each reward and the average reward . This is the differential return:

Subtracting from every reward is what makes this infinite sum converge: a policy earning exactly its own average rate contributes zero on balance, and the differential return measures only the transient advantage or deficit of starting in a particular state. The corresponding value functions are the differential value functions, defined with the same expectations as before, and , now with the differential return inside.

The differential value functions satisfy Bellman equations of the familiar shape, obtained from the discounted ones by two edits: drop every , and replace each reward by . For state values,

and for action values,

The optimality equations replace by its maximum over policies, , and take the greedy max over next actions — the same edits applied to and . There is also a differential TD error, again the discounted TD error with removed and reward replaced by reward-minus-average. For action values,

where is the current estimate at time of the average reward . (The state-value differential TD error is the same with in place of .) With these definitions, most of the algorithms and theoretical results carry over to the average-reward setting unchanged.

The two edits from the discounted to the differential Bellman/TD form. Every discount factor is dropped, and every reward is replaced by , the reward minus the current estimate of the average reward. The differential TD error is the result.

Differential semi-gradient Sarsa

Assembling the pieces gives the control algorithm for the continuing, average-reward setting. The weight update is the average-reward version of semi-gradient Sarsa: exactly equation for one-step Sarsa, but with the differential TD error in place of the discounted one,

with the differential action-value TD error above. Two things are learned at once: the weights , as always, and the average-reward estimate , which is nudged by the same TD error. Because measures how much better the last transition was than expected, its running total signals whether is set too low or too high.

Algorithm:Differential-Semi-Gradient-Sarsa\textsc{Differential-Semi-Gradient-Sarsa} — estimate q^q\hat q \approx q_\ast
  1. 1
    input: a differentiable q^:S×A×RdR\hat q : \mathcal{S} \times \mathcal{A} \times \mathbb{R}^d \to \mathbb{R}
  2. 2
    parameters: step sizes α,β>0\alpha, \beta > 0
  3. 3
    initialize wRd\mathbf{w} \in \mathbb{R}^d arbitrarily (e.g. w=0\mathbf{w} = \mathbf{0})
  4. 4
    initialize average-reward estimate RˉR\bar R \in \mathbb{R} arbitrarily (e.g. Rˉ=0\bar R = 0)
  5. 5
    initialize state SS and action AA
  6. 6
    loop
    for each step
  7. 7
    take action AA, observe R,SR, S'
  8. 8
    choose AA' as a function of q^(S,,w)\hat q(S', \cdot, \mathbf{w}) (e.g. ε\varepsilon-greedy)
  9. 9
    δRRˉ+q^(S,A,w)q^(S,A,w)\delta \gets R - \bar R + \hat q(S', A', \mathbf{w}) - \hat q(S, A, \mathbf{w})
  10. 10
    RˉRˉ+βδ\bar R \gets \bar R + \beta\, \delta
  11. 11
    ww+αδq^(S,A,w)\mathbf{w} \gets \mathbf{w} + \alpha\, \delta\, \nabla \hat q(S, A, \mathbf{w})
  12. 12
    SSS \gets S'
  13. 13
    AAA \gets A'

There is no episode loop — the interaction is one unbroken stream of steps, which is what continuing means. The average-reward estimate uses its own step size , typically smaller than , so tracks the slow drift of the policy's reward rate while adapts faster to individual states.

Worked example: the access-control queuing task

For example: ten servers face a single queue. Customers arrive with one of four priorities, paying , , , or if admitted to a free server and if rejected. Each step the agent looks at the customer at the head of the queue and either accepts (assigns a free server, if one exists) or rejects (drops the customer for zero reward). Each busy server frees itself with probability per step. The queue never empties and priorities are uniform, so the state is just the pair (number of free servers, priority of the head customer) — states — and there are two actions. The goal is to maximize long-run reward with no discounting, which is what forces the average-reward setting.

Run differential semi-gradient Sarsa with , , , all action values and starting at zero. The policy it finds is intuitive. When many servers are free, accept every customer — there is no reason to hold capacity. As free servers grow scarce, start rejecting the low-priority customers to hold capacity open for the high-priority ones still to come: with one or two free servers the agent rejects priority- and often priority- customers while still admitting priority- and priority-. The threshold is a tradeoff — rejecting a priority- customer forfeits now but keeps a server open for a possible priority- later, and that gamble only pays when free servers are few enough that the wait for a replacement is short. As a byproduct converges to the policy's true average reward, the per-step rate this accept/reject rule sustains.

The policy found by differential semi-gradient Sarsa on the access-control queuing task, as a grid over (free servers, head-customer priority). With many free servers every priority is accepted; as servers grow scarce the agent rejects the low-priority customers first to reserve capacity for high-priority ones. A = accept, R = reject.

The average-reward revival and continuous control

The differential machinery of this lesson has become more, not less, relevant as reinforcement learning has scaled to deep networks.

Average reward comes back for deep RL. This chapter argues the average-reward setting is the appropriate formulation for continuing problems under function approximation, and recent deep-RL work has taken that seriously. Naik et al. (2019), Discounted reinforcement learning is not an optimization problem, NeurIPS Optimization Foundations of RL workshop, sharpened the point that discounted control with function approximation is not optimizing a well-defined objective, and average-reward deep methods such as RVI-Q and differential Q-learning descendants (Wan, Naik & Sutton, 2021, Learning and planning in average-reward Markov decision processes, ICML) carry the differential-return machinery of this lesson into deep networks.2 The update — one scalar tracking the reward rate, nudged by the same TD error that trains the weights — carries over essentially unchanged.

Deterministic policy gradients for continuous control. When actions are continuous and the critic is differentiable, one can push the gradient of through the action into a deterministic policy: DDPG (Lillicrap et al., 2016, Continuous control with deep reinforcement learning, ICLR) and its successor TD3 (Fujimoto et al., 2018, Addressing function approximation error in actor-critic methods, ICML) do exactly this, solving the Mountain-Car-like problem of continuous throttle that the discrete action set sidesteps.3 They inherit the off-policy instabilities the next lesson names, which is why they rely on target networks and replay.

What changed, and what comes next

The mechanical part of average-reward control is small — swap the discounted TD error for the differential one, track a running estimate of the reward rate with its own step size, and drop the episode loop. What changed underneath is the whole justification. Function approximation broke discounting: the discounted objective ranks policies identically to the average-reward objective, so carries no information, and the policy improvement theorem that justified greedy control is lost. The average-reward setting replaces it — the differential return, the differential value functions, and differential semi-gradient Sarsa give a control method for continuing tasks that never invokes a discount factor at all.

One assumption remains: all of this was on-policy. The data came from the very policy being evaluated. The next lesson lets the behavior and target policies diverge, and finds that off-policy learning, bootstrapping, and function approximation together form a deadly triad that can make the weights diverge — the sharpest instability in all of approximate reinforcement learning.

Footnotes

  1. Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), §10.3 — Average Reward: A New Problem Setting for Continuing Tasks: the average reward (10.6)–(10.7), steady-state distribution (10.8), the differential return (10.9), the differential Bellman equations, the differential TD errors (10.10)–(10.11), and differential semi-gradient Sarsa (10.12). §10.4 — Deprecating the Discounted Setting: the futility-of-discounting result that the average of the discounted returns is , the symmetry argument and the boxed direct derivation , and the loss of the policy improvement theorem under function approximation. Example 10.2 — the access-control queuing task (10 servers, four priorities, , parameters , ).
  2. Naik, A. et al. (2019), Discounted reinforcement learning is not an optimization problem, NeurIPS Optimization Foundations of RL workshop — the argument that discounted control with function approximation lacks a well-defined objective. Wan, Y., Naik, A. & Sutton, R. S. (2021), Learning and planning in average-reward Markov decision processes, ICML — differential Q-learning and average-reward planning.
  3. Lillicrap, T. et al. (2016), Continuous control with deep reinforcement learning, ICLR — DDPG, deterministic policy gradients through a differentiable critic. Fujimoto, S. et al. (2018), Addressing function approximation error in actor-critic methods, ICML — TD3, correcting overestimation bias in continuous-control critics.

╌╌ END ╌╌