Approximate Solution Methods/Off-Policy Eligibility Traces

Lesson 3.131,781 words

Off-Policy Eligibility Traces

Eligibility traces meet off-policy learning and function approximation — the corner where stability gets hard. We first let the bootstrapping and discounting parameters vary with state, so a single generalized return covers episodic and continuing tasks and folds termination into the discount.

╌╌╌╌

The eligibility-traces lesson completed the on-policy case: the -return as a forward view, the trace vector as a backward view, TD() making the two nearly agree, true online TD() making them agree exactly, and Sarsa() lifting the whole apparatus to on-policy control. Throughout, and were fixed constants and every step was generated by the policy being evaluated.

This lesson removes both restrictions. First and become functions of state and action, which turns out to unify the episodic and continuing settings and absorb termination into the discount. Then we learn about a target policy from behavior policy , which brings the per-decision importance ratio into the trace, with a control variate to limit the variance. The combination — traces, off-policy data, and a parameterized value function — is the deadly triad itself, and convergence is no longer guaranteed. Naming the methods that restore stability is the job of the next lesson; this one builds the returns and traces they all rest on.

Variable λ and γ

To state the final algorithms in their most general form, promote the two constants to functions.1 Let depend on state and action, , and let depend on state, . The termination function is the significant one, because it changes the return itself — the random variable whose expectation we are estimating. The return is now defined by a running product of per-step discounts,

where we require with probability one for every , so the sums are finite. This single definition lets the episodic setting be presented as one uninterrupted stream of experience — no special terminal states, no start distribution, no explicit termination time. A former terminal state becomes an ordinary state at which and which transitions to the start distribution; setting everywhere else recovers the classical episodic case exactly.

State-dependent termination unifies the settings. Top: the classic episodic view, with a special terminal state and a reset. Bottom: the same experience as one continuing stream where the goal state has and jumps back to the start; a bootstrapping state has . Setting off the goal recovers the episodic case; a constant recovers ordinary discounting.

State-dependent termination also reaches beyond ordinary episodes to pseudo termination: predicting some quantity as if the stream ended here, without actually interrupting the Markov process. A discounted return is one such quantity, so this one construction unifies episodic, discounted-continuing, and pseudo-terminating prediction. (The undiscounted-continuing case, with no termination, still needs its own treatment via average reward.)

A worked return. Take rewards and a per-state discount that is everywhere except a goal state reached at step , where . The running product truncates the sum the moment it hits the zero: the weight on is , on is , on is , and every later reward is multiplied by . So

a finite return produced with no special terminal state and no episode boundary — the goal's truncates the sum. Set instead and the same stream keeps accumulating , the ordinary discounted return of a continuing task. One definition covers both cases.

Making variable is a change of solution strategy, not of the problem: it sets, state by state, how much to bootstrap. The generalization touches the -return, which now recurses. In the state-based case, writing the superscript to mark that it bootstraps from state values,

Read it left to right: the return is the first reward, plus (to the extent we are not terminating, ) a second term that splits by the degree of bootstrapping — a fraction takes the estimated value at the next state, and the complementary fraction recurses into the -return of the next step. The action-based return has a Sarsa form,

and an Expected-Sarsa form that bootstraps from the expected value under the target policy,

These recursions are the substrate for everything below. Constant are the special case , , which collapses each back to the -return of the previous lesson.

Off-policy traces with control variates

Now the data is off-policy: actions come from a behavior policy while we evaluate a target policy . For -step methods, importance sampling was applied outside the return. That has no clean analogue for a full, non-truncated -return, so we move directly to the modern construction: fold the per-decision importance ratio into the return itself, with a control variate to hold the variance down.2 The per-step ratio is the usual

The state-based off-policy -return generalizes the recursion above by scaling the bootstrapped part by and adding a correction term that has zero mean but cancels much of the extra variance,

The second term is the control variate: its expectation over is zero (because ), so it does not bias the target, but when is far from it pulls the return back toward the current estimate and dampens the swing.

The control variate at work. Without it (top), a large importance ratio scales the whole target and the estimate whipsaws far from the baseline . With the correction (bottom), the same ratios produce a target that stays near the baseline; the correction has zero mean, so no bias is added.

A worked correction. Suppose at the target policy would take the sampled action with probability while the behavior policy took it with , so . Let the bracketed one-step target evaluate to and the current estimate be . Without the control variate the return is — a swing of above the baseline from a single lucky-for- action. With the control variate it is , a swing of . The correction has not changed the expectation (over , so ), but it has shrunk this particular sample's excursion from to . When instead the sampled action is one dislikes, , and the same term nudges the target back up toward the baseline — either way, toward .

The value of this form is that the truncated version can be written, to a close approximation, as a sum of state-based TD errors, exactly as in the on-policy case. With the per-decision TD error

the return is approximately

with the approximation becoming exact when the value function does not change. The product is the eligibility-trace weight: it compounds the same decay as before, now multiplied by the importance ratios along the way. The forward-view update

already looks like a trace-based TD update: a product of past terms multiplying present TD errors. Summing this forward-view update over time and applying the summation-rule rearrangement (the same manipulation used for on-policy TD()) converts it into a backward view driven by a single accumulating trace. The trace that falls out is the general accumulating trace with importance sampling,

paired with the usual semi-gradient update . In the on-policy case every and this reduces to the ordinary accumulating trace (extended to variable ); off-policy, the scaling makes the algorithm correct in expectation. But as a semi-gradient method it is not guaranteed stable — the next sections repair that.

Where the importance ratio enters the trace. The trace at decays the previous trace by , adds the new gradient, and scales the whole thing by . When agrees with , and this is the on-policy accumulating trace; a target action that rarely takes gives and amplifies the trace.

The identical derivation runs for action values. Starting from the Expected-Sarsa form of the general -return — which works out simpler than the Sarsa form — the same steps produce the action-value off-policy trace,

with the expectation-form action-value TD error

and the same weight update . This is an efficient Expected-Sarsa() that runs on-policy or off-policy; with constant and the ordinary state-action TD error it becomes exactly the Sarsa() of the previous lesson. It is probably the best method of its kind — subject, still, to the stability caveat.

Watkins's Q(λ) to Tree-Backup(λ)

The oldest way to give Q-learning eligibility traces is Watkins's Q().3 Q-learning bootstraps from the greedy action, so its trace should reflect the future only as long as the agent keeps taking greedy actions. Watkins's rule is simple: decay the trace by in the usual way as long as greedy actions are taken, but the moment the behavior policy selects the first non-greedy action, cut the trace to zero. Everything after that first exploratory step is off the greedy path and irrelevant to the greedy target, so it receives no eligibility.

Backup diagram for Watkins's Q(lambda). Component backups of increasing length are weighted (1-lambda), (1-lambda)lambda, (1-lambda)lambda^2, ..., as in any lambda-return; the series ends either at episode termination (weight lambda^{T-t-1}, the box) or at the first non-greedy action, whichever comes first. After that first non-greedy branch the trace is cut.

The cut is crude. If exploration is frequent — and early in learning it is — the trace is repeatedly truncated, so Q() rarely propagates credit more than a step or two, and much of the benefit of traces is lost. The deeper problem is that cutting on the first non-greedy action is a hard special case of a more principled operation, which removes the need for the cut entirely.

The general version is Tree-Backup(), abbreviated TB().4-step Tree Backup already extended Expected Sarsa to arbitrary target policies without any importance sampling; TB() is its eligibility-trace form, and it is arguably the true successor to Q-learning because it keeps that appealing absence of importance sampling while applying to off-policy data. Starting from the Expected-Sarsa recursion and expanding the bootstrapping case after the tree-backup pattern, the return weights each action branch by its target-policy probability,

Backup diagram for Tree-Backup(lambda). Every backup fans out to all actions at each level: the selected action (solid, continuing down) plus the unselected actions (leaf dots), each weighted by its target-policy probability pi(a|s). No importance sampling is needed — the target policy enters only through these branch weights. Component lengths are weighted 1-lambda, (1-lambda)lambda, ... exactly as before, terminating at the box.

Written approximately as a sum of TD errors, the return uses the expectation-based error and a trace weighted by the target-policy probability of each selected action,

Compare the three action-value traces. On-policy Sarsa() decays by ; the importance-sampling off-policy trace decays by ; TB() decays by . Watkins's Q() is the crude ancestor of that last form: taking a greedy action makes (no extra decay), and taking a non-greedy action makes (the trace vanishes) — which is precisely the cut on first non-greedy action rule, now recovered as a hard special case of the smooth TB() weighting. TB(), together with the standard semi-gradient update, is the tree-backup trace algorithm; like every semi-gradient method here, it is not guaranteed stable under off-policy data with a strong function approximator.

The three action-value traces share the base decay and differ only in the off-policy factor. Sarsa() uses none; the importance-sampling trace multiplies by , which can spike far above 1; TB() multiplies by , which only ever damps the trace. Watkins's Q() is TB with a hard 0/1 gate.

Where this leaves us

Two generalizations push the trace machinery to its most general form. Variable and turn the constants into functions, unify episodic and continuing tasks in a single stream, and fold termination into a state-dependent discount. Control variates fold the importance ratio into the trace and dampen the variance it brings, giving an efficient off-policy TD() and Expected-Sarsa(). Watkins's Q() cuts the trace on the first non-greedy action; Tree-Backup() replaces that hard cut with a smooth target-policy weighting and needs no importance sampling at all.

All of it is still semi-gradient, though, so whenever it bootstraps, and off-policy plus bootstrapping plus function approximation is the deadly triad — the weights can diverge. The stabilizing methods, and the practical cost of running traces, continue in stable off-policy methods with traces.

Footnotes

  1. Sutton & Barto, Reinforcement Learning: An Introduction (2nd ed.), §12.8 — Variable and : promoting and to functions , ; the generalized return (12.17) with the running product ; the termination function unifying episodic, continuing, and pseudo-terminating prediction; and the recursive generalized -returns for states (12.18), Sarsa (12.19), and Expected Sarsa (12.20)–(12.21).
  2. Sutton & Barto, §12.9 — Off-policy Traces with Control Variates: the per-decision importance ratio folded into the state-based -return with the control-variate term (12.22); the TD-error approximation (12.23)–(12.24); the general accumulating trace with importance sampling (12.25); and the action-value off-policy return (12.26)–(12.28) yielding the trace (12.29) and an Expected-Sarsa().
  3. Sutton & Barto, §12.10 — Watkins's Q(): decay the trace by while greedy actions are taken, cut it to zero on the first non-greedy action (backup diagram, Fig. 12.12).
  4. Sutton & Barto, §12.10 — Tree-Backup(), TB(): the eligibility-trace form of -step Tree Backup, requiring no importance sampling; the target-policy-weighted return and the trace (backup diagram, Fig. 12.13).

╌╌ END ╌╌