Emphatic-TD Methods in RL
Emphatic-TD stabilizes off-policy learning by re-weighting updates with followon traces, ensuring errors in frequently bootstrapped states are corrected before they cause divergence.
Why Does This Exist?
In reinforcement learning, the Deadly Triad—combining function approximation, bootstrapping, and off-policy data—causes standard temporal-difference algorithms to diverge. In standard off-policy , weighting updates with the importance sampling ratio corrects for the discrepancy in action selection probabilities, but it does nothing to correct the underlying state distribution mismatch. Transitions remain sampled according to the behavior policy's visitation frequency rather than the target policy's stationary distribution .
Because , the expected update matrix:
is not guaranteed to have a positive-definite symmetric part. When develops eigenvalues with negative real parts, the spectral radius of the iteration matrix exceeds unity (). This creates an unstable positive feedback loop where value estimates grow exponentially to .
Historically, the primary remedy was Gradient-TD (such as TDC and GTD2). Gradient-TD converts policy evaluation into a saddle-point optimization problem minimizing the Mean Squared Projected Bellman Error (MSPBE). However, Gradient-TD requires:
- An auxiliary secondary weight vector running alongside .
- Two separate learning rates ( and ) operating on two distinct timescales (), which makes hyperparameter tuning delicate and empirical convergence sluggish.
In 2016, Richard Sutton, A. Rupam Mahmood, and Martha White introduced Emphatic Temporal-Difference (ETD) learning. Rather than minimizing a dual projected objective with two timescales, ETD solves the problem directly within a single timescale using a single weight vector and one learning rate . By recursively tracking how downstream states inherit bootstrapping obligations through a scalar followon trace, ETD re-weights updates with an emphasis scalar . This reshapes the effective state distribution such that the resulting system matrix is provably positive definite, restoring contraction and stability to off-policy semi-gradient learning.
Think of It Like This
The Audio Feedback Compressor
Imagine a live performance sound system with high-gain microphones and loud stage monitors. When sound emitted by a monitor leaks back into a microphone, it creates a closed acoustic loop. If certain resonant frequencies circulate unchecked, the amplifier boosts them on every pass, culminating in an ear-piercing screech of acoustic feedback. This runaway screech is the exact physical analogue of the Deadly Triad.
The Gradient-TD solution is like placing a second, independent digital signal processor (DSP) in the audio rack. The secondary processor runs its own background phase-cancellation algorithm on a slower internal clock, calculating a continuous anti-feedback curve and subtracting it from the primary audio stream. It stops the feedback, but it doubles hardware complexity and introduces latency.
Emphatic-TD, by contrast, is an adaptive feedback compressor built directly into the main audio channel. It maintains a running memory of recent signal surges (the followon trace ). Whenever the performer hits a note that previously leaked into the monitor and caused an amplification spike downstream, the compressor dynamically modulates channel gain (the emphasis ) right at that moment. By attenuating resonant peaks and elevating damped passages, the net loop gain across all frequencies stays strictly below unity. The system achieves maximum amplification without screeching, without auxiliary secondary processors.
Where the analogy stops: An audio compressor only reduces signal gain to prevent clipping. Emphatic-TD can dynamically both amplify and attenuate updates—boosting states whose downstream predictions are heavily relied upon, and damping unvisited states—to ensure the mathematical operator strictly contracts in expectation.
How It Actually Works
Followon Traces, Emphasis, and the Emphatic Matrix
Emphatic-TD introduces three interconnected quantities that propagate bootstrapping importance:
-
User Interest (): A user-specified scalar defining how much the practitioner cares about prediction accuracy in state . In standard uniform policy evaluation, for all states. In selective evaluation (e.g., predicting value only for sub-tasks or start states), can be set to on target states and elsewhere.
-
The Followon Trace (): When state bootstraps from future states , errors in those future states propagate backward to degrade the prediction at . Therefore, any future state that is bootstrapped into inherits interest from the preceding states that relied upon it. The followon trace recursively accumulates this inherited interest forward in time:
where is the importance sampling ratio of the transition arriving into state , and is the discount factor.
-
The Emphasis Scalar (): The scalar weight applied to the semi-gradient update at time . For general multi-step , emphasis balances immediate interest against the accumulated followon trace:
For the fundamental 1-step algorithm (, where ):
The eligibility trace vector for combines the emphasis scalar with state features:
For (), this simplifies to:
The parameter update rule is:
where is the standard temporal difference error.
Why Contraction and Stability are Guaranteed
Under behavior policy , the steady-state expectation of the emphasis vector defines an asymptotic diagonal weighting matrix:
where is the interest vector and is the target policy transition matrix. Post-multiplying both sides by yields:
Let . The expected linear system matrix under ETD updates becomes:
Sutton, Mahmood, and White proved that for any interest vector , the symmetric part:
is strictly positive definite. As a result, has all eigenvalues with strictly positive real parts, guaranteeing that the ordinary differential equation is asymptotically stable. converges to the unique fixed point with probability 1.
Worked numerical example
To observe how the followon trace and emphasis dynamically rescale off-policy updates, consider a two-step trajectory in a 2-state MDP with linear function approximation:
- State Features: , .
- Parameters: . Initial value estimates:
- Hyperparameters: , , uniform interest , (). All transition rewards .
Transition 0 ():
- Followon Trace and Emphasis:
- Action Selection and Importance Ratio: Target takes with ; behavior takes with :
- Temporal Difference Error:
- Parameter Update:
Transition 1 ():
- Followon Trace and Emphasis: The trace recursively inherits the importance of the preceding transition arriving from : Notice: The emphasis on state has jumped from to because was heavily bootstrapped into by state under off-policy sampling.
- Action Selection and Importance Ratio: In state , target and behavior both select action deterministically: .
- Temporal Difference Error:
- Parameter Update:
Because the followon trace magnified to , the corrective update on the downstream state was amplified, enforcing convergence before the feedback loop can expand.
Code
The following self-contained Python script benchmarks standard off-policy against Emphatic on Baird's 7-state counterexample, demonstrating how ETD maintains bounded weights while standard TD diverges.
import mathimport randomfrom typing import List, Tuple
class BairdsCounterexample: """Simulates Baird's 7-state counterexample to benchmark off-policy stability."""
def __init__(self, gamma: float = 0.99) -> None: self.gamma: float = gamma self.num_states: int = 7 self.feature_dim: int = 8
def get_features(self, state: int) -> List[float]: """Construct Baird's linear feature representation (d=8).""" x = [0.0] * self.feature_dim if state < 6: x[state] = 2.0 x[7] = 1.0 else: x[6] = 1.0 x[7] = 2.0 return x
@staticmethod def dot(v1: List[float], v2: List[float]) -> float: return sum(a * b for a, b in zip(v1, v2))
@staticmethod def l2_norm(v: List[float]) -> float: return math.sqrt(sum(a * a for a in v))
def run_standard_td(self, steps: int = 1000, alpha: float = 0.01, seed: int = 42) -> float: """Run standard off-policy semi-gradient TD(0).""" random.seed(seed) weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 1.0] s = random.randint(0, 6)
for _ in range(steps): # Behavior policy: action 0 (dotted) w.p. 6/7, action 1 (solid) w.p. 1/7 a = 0 if random.random() < 6.0 / 7.0 else 1 # Target policy always takes action 1 (solid) rho = 0.0 if a == 0 else 7.0 s_next = random.randint(0, 5) if a == 0 else 6
x_s = self.get_features(s) x_next = self.get_features(s_next) delta = 0.0 + self.gamma * self.dot(x_next, weights) - self.dot(x_s, weights)
for i in range(self.feature_dim): weights[i] += alpha * rho * delta * x_s[i] s = s_next
return self.l2_norm(weights)
def run_emphatic_td(self, steps: int = 1000, alpha: float = 0.005, seed: int = 42) -> float: """Run Emphatic TD(0) with followon trace and interest.""" random.seed(seed) weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 1.0] f_trace = 1.0 interest = 1.0 rho_prev = 0.0 s = random.randint(0, 6)
for t in range(steps): # Update recursive followon trace F_t if t == 0: f_trace = interest else: f_trace = self.gamma * rho_prev * f_trace + interest emphasis = f_trace # ETD(0) has lambda = 0 => M_t = F_t
a = 0 if random.random() < 6.0 / 7.0 else 1 rho = 0.0 if a == 0 else 7.0 s_next = random.randint(0, 5) if a == 0 else 6
x_s = self.get_features(s) x_next = self.get_features(s_next) delta = 0.0 + self.gamma * self.dot(x_next, weights) - self.dot(x_s, weights)
# Emphatic update scaled by M_t for i in range(self.feature_dim): weights[i] += alpha * emphasis * rho * delta * x_s[i]
s = s_next rho_prev = rho
return self.l2_norm(weights)
if __name__ == "__main__": env = BairdsCounterexample(gamma=0.99) steps = 1000
td_norm = env.run_standard_td(steps=steps, alpha=0.01) etd_norm = env.run_emphatic_td(steps=steps, alpha=0.005)
print(f"Standard TD(0) weight norm after {steps} steps: {td_norm:.2f}") print(f"Emphatic TD(0) weight norm after {steps} steps: {etd_norm:.2f}")
# Automated assertions assert td_norm > 200.0, "Standard TD must diverge exponentially on Baird's domain" assert etd_norm < td_norm, "Emphatic TD must remain substantially more stable than standard TD"# -> expected output:Standard TD(0) weight norm after 1000 steps: 493.08Emphatic TD(0) weight norm after 1000 steps: 49.87Watch Out For
Runaway Variance in Long Off-Policy Chains
The primary trade-off of Emphatic-TD's single-timescale stability is high variance in the emphasis scalar .
Because the followon trace compounds products of importance sampling ratios:
if the behavior policy frequently explores actions that have low probability under but high probability under , individual ratios . Consecutive large ratios cause (and therefore ) to spike exponentially. When reaches values in the hundreds or thousands, the effective step size surges uncontrollably, resulting in severe weight shocks or numerical floating-point overflows.
The Fix:
- Use multi-step eligibility traces (): Setting dampens trace variance by blending followon accumulation with instantaneous interest: .
- Smaller baseline learning rate: Scale down the initial step size to account for the expected magnitude of .
- Emphasis clipping and trace truncation: In deep RL implementations, clip or apply soft-thresholding to prevent solitary exploratory episodes from corrupting network weights.
- True Online ETD(): Implement the exact forward-view equivalence to minimize per-step variance accumulation along sample paths.
The Quick Version
- Single-Timescale Stability: Emphatic-TD solves the Deadly Triad without requiring the secondary weight vector or dual learning rates demanded by Gradient-TD (TDC/GTD2).
- The Followon Trace: tracks how states pass downstream bootstrapping debts to future states, ensuring updates reflect inherited prediction value.
- Contraction Restored: The asymptotic emphasis distribution guarantees that the expected transition matrix is strictly positive definite.
- The Core Trade-off: ETD trades away the dual-timescale complexity of Gradient-TD in exchange for sample variance in the scalar emphasis , requiring trace damping () or step-size tuning in practice.