Temporal Credit Assignment
Which action earned the reward? Long delays, hindsight and return decomposition.
A chess game is lost on move 60 because of a pawn push on move 12. Minsky named the problem in 1961: which of many earlier actions deserves the credit, or the blame, for an outcome? Every method in this topic answers it well for short delays. This lesson measures why long delays defeat TD and Monte Carlo alike, then surveys the research that tries to do better: adapting the dials automatically, learning which earlier steps a reward depends on, carrying value back through memory, and assigning credit in hindsight. Much of it is recent and empirical, and the lesson says what each idea does and does not show.
What you’ll learn
- Define temporal credit assignment, and quantify how delay slows TD (information moves back about one step per update), how intervening noise slows Monte Carlo, and how discounting hides distant consequences.
- Explain eligibility traces, and as fixed credit-assignment rules, and how meta-gradients adapt them online.
- Explain return decomposition, synthetic returns and temporal value transport, and prove that a return-equivalent redistribution of reward leaves optimal policies unchanged.
- Derive hindsight credit assignment from Bayes' rule, and weigh its benefits against its variance.
Why long delays are hard
Minsky (1961) called it the credit-assignment problem: when success follows a long sequence of decisions, how should credit be divided among them? Temporal credit assignment asks which earlier actions mattered; structural credit assignment asks which parts of a system, such as which weights of a network. Sutton's 1984 thesis, where temporal-difference learning took shape, was titled Temporal Credit Assignment in Reinforcement Learning. Three quantities make long delays hard: how fast information about an outcome travels back, how much unrelated noise piles up on the way, and how much the objective itself discounts distant consequences.
Take a deterministic chain whose only reward, 1, comes on leaving its last state, with all values starting at 0, and step . Number the states by their distance from the end. Each episode visits in that order, so state is updated before its successor and bootstraps from the successor's value of the previous episode:
By induction on , using for , the solution is a binomial tail:
The reward's influence moves back like a counter that advances with probability per episode: the state steps from the reward needs about episodes, and with exactly . The delay costs time linearly, and in a stochastic environment every one of those steps also passes on the noise of the estimates it bootstraps from. Traces and n-step returns shortcut the chain; Monte Carlo does not need it at all.
In that chain, with , what is the value of the state 10 steps before the reward after 20 episodes? (Its true value is 1.)
Show the answer
0.59
. After 40 episodes it is above 0.999. With the same state needs about 100 episodes to reach one half (0.55 after 100 episodes), in a world with no noise at all.
Monte Carlo has no propagation delay, but it pays in variance. If steps separate an action from its consequence, and each intervening step adds independent reward noise of variance , the return's variance grows by , while the action's effect on the return stays fixed. The number of episodes needed to see the effect at a given confidence grows like : linearly in the length of the distraction.
Discounting hides the consequence altogether. An effect steps away enters the discounted objective with weight ; with and that is about . An agent that optimizes the discounted return barely cares about the consequence, and its estimates of it are buried under the noise of everything nearer.
Traces, λ and γ as hand-made credit rules
An eligibility trace is a fixed credit-assignment rule: a TD error at time credits the visit at time with weight , by recency, and with accumulating traces also by frequency. It knows nothing about which earlier step mattered. A key picked up 500 steps before the door it opens fades exactly like every irrelevant step in between. trades bias against variance, and plays two roles at once: it defines the objective, and it limits how far back credit can usefully flow.
Meta-gradients (Xu, van Hasselt & Silver, 2018) stop choosing these by hand. Let parameterize the return the agent learns from. After an update on experience , the agent measures the result on fresh experience with an objective that uses fixed reference parameters, and differentiates through the update:
Gradient steps on adapt the return online. On 57 Atari games over 200 million frames, the authors reported a new state-of-the-art score at the time. The rule is still geometric, though: meta-gradients tune how fast credit fades, not where it goes.
An agent picks up a key, wanders through 300 steps of unrelated activity, then opens a door with it for . Using TD(λ) with , about how much of the door's TD error reaches the key pickup through the trace?
- About 5%, the same fraction that reaches any step 300 steps back, relevant or not
- All of it, because the key caused the reward
- None, because traces only reach the previous step
- About 99%, because is close to 1
Show the answer
A. About 5%, the same fraction that reaches any step 300 steps back, relevant or not
. The trace weight depends only on elapsed time. The key pickup gets the same small share as any other step 300 steps back, and the irrelevant steps in between get larger shares. Learned decompositions and hindsight methods try to direct credit to the key instead.
Learning where credit belongs
Return decomposition. RUDDER (Arjona-Medina, Gillhofer, Widrich, Unterthiner, Brandstetter & Hochreiter, 2019) learns where an episode's reward comes from. A sequence model (an LSTM in the paper) is trained to predict the episode's return from each prefix of its trajectory, and the change in its prediction becomes a new reward,
A step that makes the predicted return jump, such as picking up the key, receives the credit at once, however long before the door it happens. (This difference of predictions is the simplest of the contribution analyses the authors use.) The return decomposition is safe for the reason the derivation shows.
The redistributed rewards of an episode telescope; , the prediction before any step, is a constant :
If the prediction is exact once the whole trajectory is known, , every episode's new return is its old return minus the same constant, and so is every policy's expected return. The ordering of policies, and with it the set of optimal ones, is unchanged: the problems are return-equivalent. A practical method can enforce exactness by giving the prediction's leftover error to the last step, which leaves that part of the reward delayed.
The payoff: with an ideal redistribution the expected reward still to come after each step is zero, since the prediction already accounts for it. Action values then equal expected immediate redistributed rewards, and learning them needs neither long chains of bootstrapping nor long noisy returns. On artificial tasks with delayed rewards the authors report learning far faster than Monte Carlo, and exponentially faster than TD(λ), MCTS and reward shaping as the delay grows; added to PPO on Atari, RUDDER improved scores, most of all on games with delayed rewards.
Synthetic returns (Raposo et al., 2021) learn associations between states and distant rewards directly: a model explains each reward through learned contributions of the earlier states of the episode, and a state's contribution is then used as an additional, synthetic reward, so ordinary TD learning sees the credit early. The learned contributions spike at states that follow critical actions. An IMPALA-based agent with synthetic returns solved Atari Skiing, a game with a long reward delay that had resisted deep RL agents, by the authors' account "25 times faster" than the published state of the art.
Temporal value transport (Hung et al., 2019) uses memory instead. The agent writes to an external memory and reads it by attention. When, at a later time, a read attends strongly to a memory written at an earlier time, TVT adds the value estimated at the later time, weighted by the attention, to the reward at the earlier time. Value jumps the gap directly, without passing through the discounted, noisy steps in between. In tasks where an early action matters only after a long phase of unrelated rewards, agents with TVT learned what standard agents with discounting could not.
| Approach | What is learned | How credit reaches the past |
|---|---|---|
| Eligibility traces | nothing: a fixed rule | back in time, fading by per step |
| Meta-gradient , (Xu et al., 2018) | the fading rate | the same geometric rule, tuned online |
| RUDDER (Arjona-Medina et al., 2019) | a return predictor | reward moved to the steps that change the prediction |
| Synthetic returns (Raposo et al., 2021) | contributions of past states to rewards | a synthetic reward at the contributing states |
| TVT (Hung et al., 2019) | a memory read by attention | value added to the reward of the recalled time step |
| Hindsight credit assignment (Harutyunyan et al., 2019) | the probability of each action given the outcome | every outcome reweighted for every action, next step |
Hindsight: credit from outcomes
Hindsight credit assignment (Harutyunyan et al., 2019) turns the question around. Instead of asking what an action will lead to, ask, once an outcome is known, how likely each action was to have produced it. Bayes' rule makes this exact.
Let be the return of a trajectory that starts in state and follows , first action included, and define the hindsight distribution . By Bayes' rule,
Solve for and average : the value of action is a reweighting of returns that followed any action:
The same argument with the state reached steps later, using and the fact that the reward after depends on the first action only through when actions follow , gives the state-conditional form.
In return-conditional hindsight credit assignment, suppose the return is independent of the first action. What weight does a return receive, for each action ?
- 0 for every action, so no learning happens
- 1 for every action, so every action receives the same value: none gets spurious credit
- , the importance ratio
- It depends on the action that was actually taken
Show the answer
B. 1 for every action, so every action receives the same value: none gets spurious credit
If carries no information about , then and every ratio is 1: each action's estimate is the plain average return. Credit flows to an action only to the extent that it made the observed outcome more (ratio above 1) or less (below 1) likely. That is how hindsight methods reduce the noise that irrelevant actions add to credit.
The gains: every trajectory from informs the value of every action, and an action is credited in proportion to how much it changed the probability of what happened. The costs: must be learned, typically as a classifier that predicts the first action from the state and the outcome, and its errors bias the estimates; and the ratio is large wherever is small, which can raise the variance. The original paper demonstrated the method on illustrative tasks built to isolate credit-assignment difficulties. Counterfactual credit assignment (Mesnard et al., 2021) carries the idea into policy gradients, with baselines computed from learned summaries of the future and constrained so that the gradient stays unbiased.
Key takeaways
- Temporal credit assignment asks which earlier actions deserve credit for an outcome (Minsky, 1961). In a chain, TD(0)'s value steps from a reward after episodes is : information travels back about one step per update.
- Monte Carlo avoids the propagation delay but its variance grows with every noisy step between action and consequence, and discounting weights a consequence steps away by .
- Eligibility traces credit by recency alone; meta-gradients can tune and online, but cannot direct credit to the step that mattered.
- Return decomposition (RUDDER) moves reward to the steps that change a learned return prediction; an exact redistribution is return-equivalent and keeps the optimal policies. Synthetic returns and temporal value transport learn associations or use memory to carry credit across long gaps.
- Hindsight credit assignment weights each outcome by for every action, so actions without influence get no spurious credit; its costs are a learned model and possibly large ratios. Benchmarks and guarantees for long-term credit assignment remain open.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In a deterministic chain whose only reward comes steps after its first state, TD(0) runs with and values starting at 0. After how many episodes does the first state's value first reflect the reward?
- 1
- Never, since TD(0) bootstraps
Show the answer
B.
With , : each episode moves the information back exactly one state, so the state steps from the reward first sees it in episode . Monte Carlo, or TD(1), would update it after the first episode.
Why does Monte Carlo struggle when a long stretch of unrelated, noisy rewards separates an action from its consequence?
- Because Monte Carlo must wait for the episode to end
- Because Monte Carlo returns are biased by the noise
- Because the noise of every intervening reward adds to the return's variance while the action's effect stays the same, so more episodes are needed to detect it
- Because Monte Carlo cannot handle discounting
Show the answer
C. Because the noise of every intervening reward adds to the return's variance while the action's effect stays the same, so more episodes are needed to detect it
The return stays unbiased, but its variance grows by about per noisy step, so the episodes needed to detect an effect grow like . TD reduces the variance by bootstrapping, at the price of the propagation delay; neither solves the problem for very long gaps.
RUDDER replaces each reward by the change in a learned prediction of the episode's return, . Why does this leave the optimal policies unchanged, in undiscounted episodic tasks?
- Because the redistributed rewards telescope to the episode's return minus a constant, if the final prediction is exact, so every policy's expected return shifts by the same constant
- Because the predictor is trained on optimal trajectories only
- Because the new rewards are potential-based shaping with
- It does not: redistribution always changes the optimal policy
Show the answer
A. Because the redistributed rewards telescope to the episode's return minus a constant, if the final prediction is exact, so every policy's expected return shifts by the same constant
when the final prediction equals the return. A shift shared by all policies cannot change which is best. If the final prediction is off, the leftover error must be returned to the episode, for instance at its last step, to keep this guarantee.
In return-conditional hindsight credit assignment, how does a sampled return from state enter the estimate of ?
- Only if was the action actually taken, with weight 1
- With weight , an importance ratio
- With weight , for every action , whichever was taken
- With weight , where is the length of the episode
Show the answer
C. With weight , for every action , whichever was taken
By Bayes' rule, , so . One return informs every action, more for actions that made it more likely.
Further reading
- M. Minsky, "Steps toward artificial intelligence," Proceedings of the IRE 49(1), 8–30 (1961).
- J. A. Arjona-Medina, M. Gillhofer, M. Widrich, T. Unterthiner, J. Brandstetter & S. Hochreiter, "RUDDER: Return decomposition for delayed rewards," Advances in Neural Information Processing Systems 32 (2019).
- A. Harutyunyan, W. Dabney, T. Mesnard, M. Gheshlaghi Azar, B. Piot, N. Heess, H. van Hasselt, G. Wayne, S. Singh, D. Precup & R. Munos, "Hindsight credit assignment," Advances in Neural Information Processing Systems 32 (2019).
- C.-C. Hung, T. Lillicrap, J. Abramson, Y. Wu, M. Mirza, F. Carnevale, A. Ahuja & G. Wayne, "Optimizing agent behavior over long time scales by transporting value," Nature Communications 10, 5223 (2019).
- E. Pignatelli, J. Ferret, M. Geist, T. Mesnard, H. van Hasselt, O. Pietquin & L. Toni, "A survey of temporal credit assignment in deep reinforcement learning," arXiv:2312.01072 (2023).