Eligibility traces are short-term, decaying memory variables in reinforcement learning that record how recently and how often each state, action or weight has contributed to the agent’s behavior, so that a single temporal difference error can update all recently relevant estimates at once. They are the mechanism behind TD(λ), also written TD lambda, and its control variants such as Sarsa(λ).
Eligibility traces address the credit assignment problem in time. Instead of waiting until the end of an episode, as Monte Carlo methods do, or crediting only the previous step, as one-step temporal difference learning does, traces let the agent blend both extremes through a single parameter, lambda, between 0 and 1.
How eligibility traces assign credit
At every time step the agent computes a temporal difference error, the difference between the reward plus the discounted value of the next state and the current value estimate. With eligibility traces, this error does not update only the current state. It updates every state in proportion to its trace, so states visited moments ago receive a strong update and states visited long ago receive a weak one.
Each trace follows a simple rule. On every step all traces decay by the factor gamma times lambda, where gamma is the discount factor. The trace of the state just visited is then increased. With linear function approximation, the trace becomes a vector the same size as the weights and accumulates the gradient of the value estimate, which is why it is often described as a short-term memory of the gradient.
The table summarizes the quantities involved in a TD(λ) update.
| Symbol | Meaning | Typical range |
|---|---|---|
| Lambda (λ) | Trace decay; sets how far credit flows backward | 0 to 1, often 0.8 to 0.95 |
| Gamma (γ) | Discount factor for future rewards | 0.9 to 0.999 |
| Alpha (α) | Step size of the weight update | Small, problem dependent |
| Delta (δ) | Temporal difference error at the current step | Any real number |
| Trace (e) | Eligibility of each state or weight | Nonnegative for tabular cases |
The forward view and the backward view
Eligibility traces have two equivalent descriptions. The forward view defines the target as the lambda-return, a weighted average of all n-step returns, with weight proportional to lambda raised to the power n minus one. This view explains what TD(λ) is trying to estimate but cannot be computed online, because it needs future rewards.
The backward view is the practical algorithm. It keeps traces and applies the current error to past states, so updates happen incrementally at every step without storing the future. For offline updates the two views produce identical results, and the true online TD(λ) algorithm with dutch traces makes them match exactly even when updates are applied online.
The following table shows how lambda moves the method between its two extremes.
| Lambda value | Equivalent method | Bias and variance |
|---|---|---|
| λ = 0 | One-step TD, TD(0) | Higher bias, lowest variance |
| 0 < λ < 1 | Weighted mix of n-step returns | Balanced; usually best in practice |
| λ = 1 | Monte Carlo return for episodic tasks | No bootstrapping bias, highest variance |
Types of eligibility traces
Several trace variants differ in how they handle repeated visits to the same state. The choice matters most when an agent loops through the same states many times within an episode, because unbounded accumulation can make updates unstable.
| Variant | Update on visit | Main property |
|---|---|---|
| Accumulating trace | Add 1 to the existing trace | Original form; can exceed 1 on repeated visits |
| Replacing trace | Reset the trace to 1 | More stable with frequent revisits |
| Dutch trace | Interpolated update tied to the step size | Exact equivalence in true online TD(λ) |
| Watkins trace | Cut to zero after an exploratory action | Keeps Q(λ) off-policy correct |
For control, Sarsa(λ) keeps traces over state-action pairs and is on-policy. Watkins’s Q(λ) cuts traces whenever the agent takes a non-greedy action, which preserves correctness for off-policy learning but often makes traces very short. Later off-policy methods such as Retrace and Tree Backup use importance-weighted or truncated traces to keep credit flowing safely.
Eligibility traces in deep reinforcement learning
Classic per-weight traces fit poorly with deep networks trained from experience replay, because replayed transitions are sampled out of order and the trace history no longer matches the stored data. Modern systems therefore implement the same idea through multi-step and lambda-returns computed over stored trajectory segments.
The most widely used example is generalized advantage estimation, which applies the lambda-return idea to advantage estimates in policy gradient methods such as proximal policy optimization. Its lambda parameter plays exactly the role of the trace decay, with values around 0.9 to 0.97 being common. Value-based agents such as Rainbow DQN rely on n-step returns, a fixed-horizon relative of eligibility traces.
Practical guidance and common mistakes
Eligibility traces help most when rewards are delayed and when episodes are long, because they propagate a reward back through many earlier states in a single pass. Their benefit is smaller when rewards are dense and immediate or when computation per step is the bottleneck, since traces add work for every eligible state.
- Forgetting to reset traces at the start of each episode leaks credit across unrelated episodes.
- Using accumulating traces with large step sizes can cause divergence; replacing or dutch traces are safer.
- Ignoring off-policy corrections with Q-learning style updates biases the estimates.
- Choosing lambda without tuning wastes the main benefit; intermediate values typically outperform both extremes.
Explained without jargon
Picture a dog learning a trick. It sits, turns and then gets a treat. Which action earned the treat? Probably all of them, with the latest one mattering most. Eligibility traces keep a fading note of recent actions.
When a reward or a surprise arrives, the learner shares the credit among recent actions. Fresh actions get more credit. Older ones get less. This helps an agent learn faster from delayed rewards.
A typical use case
A research team trains an agent in the classic mountain car task, where an underpowered car must rock back and forth to climb a hill. The agent receives a penalty of minus one each step until it reaches the goal, so useful feedback is delayed by hundreds of steps.
Using linear Sarsa with tile coding and λ = 0, the agent needs several hundred episodes to learn a reliable swinging strategy. Switching to Sarsa(λ) with replacing traces and λ = 0.9 spreads each error back across the recent swing, and the agent reaches comparable performance in a fraction of the episodes. The team keeps λ at 0.9 after a short sweep shows that both 0 and 1 perform worse than intermediate values.