TL;DR
A standard reinforcement learning agent learns to do one task, defined by one reward function. Goal-conditioned reinforcement learning gives the agent a goal as an extra input, so one policy and one value function can handle many goals. The agent learns how to reach any target it is asked for, not just the one it was trained on.
Where you'll see it: robot arms that must reach arbitrary positions, navigation to any location, and language-conditioned agents that follow instructions naming different outcomes.
Intuition
One map, many destinations
Think of a taxi driver who knows the whole city. They do not learn one route from home to the airport and then start over for the next trip. They learn how streets connect, and any destination becomes a question they can answer. Goal-conditioned RL aims for the same property: the policy asks "where am I, and where am I going?" and acts on both.
The naive alternative is one agent per goal. That works for three goals, but a robot that must reach any point in a room would need infinitely many agents, and each one would learn from scratch. Nothing learned while reaching one point helps with another. Conditioning on the goal lets experience be shared. A step that moved the arm toward one target also teaches the agent how the arm responds to actions in general.
Why the goal must be an input
If the goal were fixed inside the reward, the value function would only ever answer one question. Making the goal an input means the value function answers a whole family of questions at once: "how good is this state if the target is that?" A neural network can represent that family as one function of the state and the goal. This is the idea that Schaul and colleagues called a universal value function approximator in 2015.
The reward is usually sparse. The agent gets a signal only when it reaches the goal, and nothing otherwise. Sparse rewards are hard to learn from, because most episodes teach almost nothing. Goal-conditioned learning has a helpful trick for this, which the math section introduces: the agent can treat a state it did reach as if that state had been the goal all along.
The math
A goal-conditioned Markov decision process is a Markov Decision Process with an extra goal variable. It has states , actions , goals , transition probabilities , a discount factor , and a reward that depends on the goal. A common sparse reward is when the agent reaches the goal on this step and otherwise.
For a policy that takes the goal as input, the value of a state under goal is
The action-value function is defined the same way, with the first action fixed to .
Here is the expected value over the randomness of the transitions and the policy, is the discount that makes later rewards count for less, and , are the state and action at step . The only change from ordinary RL is the extra argument everywhere.
The Bellman equation with a goal
The recursion from Value Function still holds, with the goal carried along:
Learning uses the same tools as Q-Learning or the critic in Actor-Critic Methods. The difference is in the data. Each stored transition can be used to update the value for its goal, and a deep network approximates as a Feedforward Neural Network with , and concatenated as input.
Hindsight relabelling
Suppose the agent was asked for goal and reached state instead. Under the sparse reward, the whole episode gives zero reward, and nothing is learned. The trick is to replace with the achieved state and recompute the reward. The episode now succeeded at a goal that was true for it, so the reward is at the end. This is the core of hindsight experience replay, and it is valid because the transitions and the policy do not depend on which goal was asked for, only on the state and action.
Worked examples
The agent stands on cells to and moves left or right by one cell. Movement is deterministic. The reward is given on the step that enters goal , and otherwise. Use .
Let be the distance from the state to the goal. The agent needs moves, and the reward arrives on the last one, so under the best policy
- Goal , state . The distance is , so .
- Check with the Bellman equation. Moving right from gives reward and lands on . Then , because one more move enters the goal. So . This matches step 1.
- Goal , state . The distance is again , so .
- Goal , state . The distance is , so .
Interpretation: one function of gives the answer for every goal. The same rule covers goals to the left and right, and the value falls off with distance at the rate set by . A single learned network that captures this rule answers the question for any goal in the corridor.
- gamma = 0.9
- gamma = 0.5
The agent is asked for goal and walks right twice, from cell to cell . It never reaches , so the sparse reward is on every step. Store the episode with and a learning rate of 1 for clarity.
- Original transitions: with reward , and with reward . Both give zero learning signal.
- Relabel with the achieved final state . Now the episode reached its goal at the last step, so the reward on is .
- Update the last transition. Its target is , since is terminal for goal . So .
- Update the first transition under the relabelled goal. Its target is . So .
- Compare with the original goal. The same episode left and unchanged at zero, because the reward was never earned for goal .
Interpretation: the failed run taught the agent two correct facts about reaching cell . It did not need to succeed at its original task to learn something useful. The relabelling is safe here because the transition dynamics do not depend on which goal was asked for.
Tradeoffs and failure modes
Goal conditioning helps when the goals share structure, so that skills transfer between them. It does not help if every goal needs a completely different strategy, and it adds input dimensions that make learning harder.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Sparse reward, goals far apart | Almost every episode gives zero signal | Hindsight relabelling of achieved states, as in Hindsight Experience Replay |
| Goals drawn from a large or continuous set | Value must generalise across goals, and bad generalisation gives confident wrong values | Reward shaping by distance, or a learned embedding of the goal |
| Goal is a whole state (an image, a full arm pose) | The input is high-dimensional and the goal space has many irrelevant features | Achieved-goal and desired-goal projections onto task-relevant features |
| Goals that are unreachable | Relabelling can teach the agent to chase states it cannot control | Restrict relabelling to states the agent can actually reach |
| Policy and value trained on different goal distributions | Value estimates are accurate only for goals seen in training | Sample goals from the same distribution used at test time |
A second failure mode is the bias that relabelling introduces. Relabelled episodes are not samples from the goal distribution the agent will face, so mixing them with original goals can shift the policy toward the goals it happened to reach. Most implementations keep a mix and tune the fraction of relabelled goals.
History
The idea of a policy that is told what to achieve is older than deep learning. Kaelbling's 1993 work on learning to achieve goals is an early example of treating goals as an input to learned behaviour. Schaul, Horgan, Gregor and Silver introduced universal value function approximators in 2015, which made the value function itself depend on the goal and showed how a single network could represent it. The problem they were solving was transfer: an agent should reuse what it learned about one goal when asked for another.
Andrychowicz and colleagues added hindsight experience replay in 2017. Their contribution was the relabelling trick above, which turns failed episodes into training data for goals the agent did reach. Their experiments used simulated robot-arm pushing, sliding and pick-and-place tasks with sparse, binary rewards, which they reported were hard to learn without relabelling.
Check yourself
QuestionWhy does a single goal-conditioned value function V(s, g) help more than one value function per goal?Show answer
Experience is shared across goals. A transition that moved the agent toward one target also tells the network how actions change the state in general, which helps for every other target. Separate value functions per goal learn from scratch for each one and cannot reuse anything.
QuestionIn the corridor example, what is V*(0, 4) with gamma = 0.9 and the sparse reward?Show answer
The distance from 0 to 4 is 4 moves, so the reward arrives on the fourth move and is discounted three times. V*(0, 4) = 0.9 to the power 3, which is 0.729.
QuestionAn agent is asked for goal 4, walks to cell 2 and stops. Why can relabelling the episode with goal 2 be useful, and what would make it wrong?Show answer
Relabelling turns the failed run into a success for goal 2, so the reward at the last step is 1 and the value of reaching cell 2 is learned. It is wrong if the goal 2 cannot be controlled, or if the policy will later be asked only for goals far from the states it can reach, since the relabelled data then does not match the distribution the agent is tested on.
QuestionWhy is the reward in the sparse setting hard to learn from, and what does goal conditioning add to the fix?Show answer
Most episodes earn zero reward, so most updates carry no information about which actions were good. Goal conditioning adds a way to reuse those episodes: any state the agent reached can serve as a goal, so the same run gives a non-zero reward for some goal.
QuestionWrite the Bellman equation for Q*(s, a, g) in words, and say which term carries the goal.Show answer
The value of taking action a in state s toward goal g is the expected immediate reward for that goal, plus the discounted best value of the next state, still toward the same goal g. The goal appears in the reward and in every later value, because the target is fixed for the whole episode.
Sources
- Wikipedia: Reinforcement learning
- Sutton and Barto, Reinforcement Learning: An Introduction (2nd edition): http://incompleteideas.net/book/the-book-2nd.html
- Andrychowicz et al. (2017), Hindsight Experience Replay: https://arxiv.org/abs/1707.01495
- Schaul, Horgan, Gregor and Silver (2015), Universal Value Function Approximators: http://proceedings.mlr.press/v37/schaul15.html