TL;DR
A sparse reward problem is a reinforcement learning task where almost every step gives reward zero, and only a few states, such as reaching a goal, give a nonzero reward. The agent learns from reward, so with almost no signal it has little to improve on, and random exploration can take a very long time to find the first reward. The difficulty grows with how far the goal is from where the agent starts.
Where you'll see it: robot manipulation, where the only reward is "the object is in the target place", and games where the score arrives only at the end of a level. It is the problem that hindsight experience replay was designed to address.
Intuition
A treasure hunt with no warmer or colder
Imagine a long corridor with a treasure at one end. You are blindfolded and can take one step left or right at a time. At each step someone tells you "nothing" until you find the treasure, when they say "found it". You have no sense of whether you are getting closer.
A blindfolded walker in a corridor with no feedback will wander. Each step is a coin toss, so the walk tends to drift back and forth. The reward, the treasure, is far away, and the only information you get is that you have not found it yet. Learning in this setting is hard for the same reason: nothing distinguishes a good step from a bad one until the treasure is reached.
Now suppose the same person says "warmer" or "colder" at every step. The search becomes easy. That is the difference between a dense reward, which gives feedback often, and a sparse one, which gives it rarely.
Why the agent cannot learn what it never sees
In reinforcement learning, the agent improves its choices using the reward it receives. A Value Function estimates the total future reward from each state, and an update moves the estimate towards what was actually observed. If every observed reward is zero, every estimate stays at zero, and the update has nothing to move towards. The agent is not failing to learn the right thing. It has no evidence about what is right.
- expected steps to first reward
- distance to reward
The math
A sparse reward problem is a Markov decision process in which the reward is zero for nearly all state-action pairs. Let be the reward after step . Sparsity means that for most times , , and that the set of states with a nonzero reward is small compared with .
The return and discounting
The quantity that the agent maximises is the discounted return
where is the discount factor. Under sparsity, is zero for most starting points, because the first nonzero term is far in the future. A reward that arrives steps later is worth of its face value now. For example, with and a reward ten steps away, the discount is . So even the signal that does exist is weakened by distance.
How long a random walker waits
Take the simplest sparse task. States are the integers on a line. The agent starts at , moves left or right with equal chance, and stays at if it tries to move left from there. The only reward is at , where the episode ends.
Let be the expected number of steps to reach from state . Then , and for
The solution is . Check for : and . Substituting gives , so .
The result is the main reason sparse rewards are hard. The expected time grows with the square of the distance, so doubling the length of the corridor quadruples the wait. A real task has far more than one dimension, and the number of states grows much faster than the length of the corridor.
Reward shaping
One remedy is to add an extra term to the reward. A common form is potential-based shaping. Choose a function that estimates progress, and define the shaped reward as
Adding to the reward leaves the optimal policy unchanged, a result that the reward shaping literature established in the late 1990s. Along any trajectory the shaping terms telescope, so their discounted sum depends only on the start and end states. The usual choice is , which rewards moving closer to the goal.
Worked examples
Use the corridor from the math section with , a random walk starting at , and reward only at .
- The expected number of steps to reach is .
- Doubling the corridor to gives .
- Under , a reward at steps is worth of its face value at the start.
- Combining both: the expected wait is 100 steps, and the reward that finally arrives is worth about a third of its face value.
Interpretation: the agent spends a hundred steps on average before it gets any signal at all. Doubling the corridor makes the wait four times as long, even though the reward itself has not changed.
A robot is on a grid, and the goal is at distance 5 from its starting cell. Use and .
- Before the move, the distance is 5, so .
- After one step towards the goal, the distance is 4, so .
- The shaping term is .
- A move away from the goal gives , so .
Interpretation: the shaped reward is positive for progress and negative for retreat, so the agent gets a signal on every step. Over a whole trajectory the shaping terms add up to a value that depends only on the start and end cells, so the best policy for the original task is unchanged.
Suppose a policy succeeds on a random 1 in 1,000,000 episodes, and each episode takes 100 steps.
- Expected number of episodes to see one success: .
- Expected number of steps: .
- At 1,000 steps per second of simulation, that is seconds, about 28 hours.
Interpretation: a sparse signal can be rare enough that collecting it takes days even with fast simulation. This is why the methods that help are the ones that either make the rare event more common, through shaping or better exploration, or extract more from each rare event, through relabelling.
Tradeoffs and failure modes
Sparse rewards are often the true objective, and they are the honest specification. Dense rewards are easier to learn from but can mislead the agent. The table summarises the usual choices.
| Situation | Problem | Better choice |
|---|---|---|
| The goal is reachable by chance | Random exploration finds reward eventually | Plain RL with a long training budget |
| The goal is far from the start | Waiting time grows with the square of the distance | Shaping, or curriculum that starts close to the goal |
| Many goals in one environment | A reward for only one goal wastes most experience | Relabelling past experience with the goals it reached, as in Hindsight Experience Replay |
| The shaping term is hand-designed | The agent may optimise the shaping rather than the task | Potential-based shaping, which preserves the optimal policy |
| Dense intrinsic rewards from curiosity | The agent may chase novelty rather than the task | Use the task reward for evaluation, and anneal the bonus |
Failure modes to watch for:
- Reward hacking under shaping. A shaping term that is not potential-based can change the optimal policy, so the agent learns to collect shaping reward instead of finishing the task. Potential-based shaping avoids this.
- Silent plateaus. A sparse-reward agent can show a flat learning curve for a long time and look broken. The flat curve is the expected behaviour before the first success, not evidence of a bug.
- Overfitting to the rare successes. With very few successes, the value estimates rest on little data. Check how many successful episodes the agent has actually seen.
- Choosing a discount that erases the signal. A small makes distant rewards nearly worthless. Lowering to speed up learning can stop the agent from valuing the goal at all.
History
Reward as the only training signal is the core idea of Reinforcement Learning as presented in the textbook by Sutton and Barto, and the delay between an action and its reward is a standard difficulty in it. The sparse reward problem is the extreme form of that delay, where reward is so rare that the delay dominates.
Reward shaping as a principled tool was developed in the late 1990s. The result that potential-based shaping preserves the optimal policy is usually attributed to Ng, Harada and Russell, and it is the reason the form is preferred over arbitrary bonuses.
Hindsight relabelling, which turns failed episodes into successes for a different goal, was proposed more recently, and it addresses sparsity by reusing the experience the agent already has.
Check yourself
QuestionIn your own words, why does a sparse reward make learning hard even if the agent is capable of solving the task?Show answer
The agent learns by moving its value estimates towards observed rewards. If almost every observed reward is zero, the estimates have nothing to move towards, so the agent cannot tell a good action from a bad one until it reaches a reward by chance. The difficulty is a lack of evidence, not a lack of ability.
QuestionA random walker on the states 0 to 6 starts at 0, moves left or right with equal chance (staying at 0 when it tries to go left from there), and receives reward only at 6. What is the expected number of steps to reach 6? Show the reasoning.Show answer
The expected time from to on this walk is . Here , so the expected time is steps. The reasoning is the recurrence with and , whose solution is .
QuestionWhy is potential-based shaping safe, when an arbitrary bonus for progress is not?Show answer
Along any trajectory the shaping terms telescope. Their discounted sum depends only on the start and end states, not on the path taken. Because the total extra reward is fixed by the endpoints (it shifts each state's value by and nothing else), the ranking of actions in every state is unchanged, so the optimal policy is preserved. An arbitrary bonus can reward behaviour that the original task does not value, which lets the agent optimise the bonus instead.
QuestionYou are training a robot to pick up an object, with reward only when the object is in the target box. After a day of training the success rate is still zero. Which change would you try first, and what would you watch for?Show answer
Start from a curriculum, placing the object close to the box so the agent sees success early, and gradually move it further away. Watch for whether the success rate becomes nonzero. If the curriculum works, check that the agent still succeeds at the full distance, because a curriculum can leave gaps in what the agent has learned. Shaping with a potential based on the distance to the box is a second option, provided it is potential-based.
Sources
- Sutton and Barto, Reinforcement Learning: An Introduction, 2nd edition (2018).
- Reinforcement learning on Wikipedia.