Skip to content
AI360Xpert
Beta

Goal-Conditioned Reinforcement Learning

One policy learns many goals at once by taking the target as input. The same network walks to any destination instead of retraining per address.

One goal conditioned value function scores state goal pairs, and at gamma 0.9 north gives minus 5.22 while south gives minus 6.13
One goal conditioned value function scores state goal pairs, and at gamma 0.9 north gives minus 5.22 while south gives minus 6.13

Why Does This Exist?

A fixed policy bakes in one destination. Move the target and it fails, even when the physics did not change. Training one network per goal ignores shared structure and scales badly.

Goal conditioned RL feeds the goal gg into policy π(a∣s,g)\pi(a \mid s, g) and value Q(s,a,g)Q(s, a, g), after Kaelbling and UVFA work by Schaul and coauthors. One net then serves many tasks, failures can be relabeled as wins for the place actually reached in hindsight experience replay, and higher levels in hierarchical RL can command subgoals through the same interface.

The one idea you need first

A goal space G\mathcal{G} lists possible targets, often a subset of states via map ϕ(s)\phi(s). Reward is usually sparse: 00 when close enough to gg, −1-1 otherwise. Sparse keeps shortest path incentives clean where dense distance can trap the agent behind walls.

Think of It Like This

A GPS unit, not a fixed commute

A fixed commuter only knows office to home. Ask for the airport and it blanks. A GPS takes current position plus destination and gives turn by turn moves for any pair.

The value V(s,g)V(s, g) is travel time between any two pins. Miss an exit and it recomputes from the new state. Reach the wrong lot and it still learned that route, which hindsight later reuses.

Where it stops: a GPS starts with a surveyed map. The agent starts with none and learns distances by trial.

How It Actually Works

Inputs are state ss and goal gg. Two builds exist. Joint concat runs [s;g;a][s; g; a] through one MLP for QθQ_{\theta}. Factored build encodes ϕ(s)\phi(s) and ψ(g)\psi(g) separately and dots them for VV, which helps lookup across many goals.

Bellman holds per goal:

Q∗(s,a,g)=R(s,a,g)+γmax⁡a′Q∗(s′,a′,g)Q^*(s, a, g) = R(s, a, g) + \gamma \max_{a'} Q^*(s', a', g)

In words: immediate goal reward plus discounted best future value for the same gg. Replay stores (s,a,s′,g)(s, a, s', g) and minimizes TD error across sampled goals.

Worked example

Stand at s=[1.0,1.0]s = [1.0, 1.0], target g=[4.0,4.0]g = [4.0, 4.0], γ=0.90\gamma = 0.90, step penalty −1.0-1.0, terminal 0.00.0. North goes to [1.0,2.0][1.0, 2.0] with 66 steps left; south goes to [1.0,0.0][1.0, 0.0] with 88 steps left.

Optimal remaining value for DD steps of −1-1 is −(1−γD)/(1−γ)-(1 - \gamma^D)/(1 - \gamma). So γ6=0.531441\gamma^6 = 0.531441 gives VN=−(1−0.531441)/0.10=−4.6856V_N = -(1 - 0.531441)/0.10 = -4.6856. And γ8=0.430467\gamma^8 = 0.430467 gives VS=−(1−0.430467)/0.10=−5.6953V_S = -(1 - 0.430467)/0.10 = -5.6953.

Bellman Q adds one penalty step:

  • QN=−1.00+0.90×(−4.6856)=−5.217Q_N = -1.00 + 0.90 \times (-4.6856) = -5.217
  • QS=−1.00+0.90×(−5.6953)=−6.126Q_S = -1.00 + 0.90 \times (-5.6953) = -6.126

Since −5.217-5.217 beats −6.126-6.126, the policy picks north toward the goal.

Code

Same choice in code:

import numpy as np

def remaining_value(steps: int, gamma: float = 0.90) -> float:    """Discounted sum of -1 for D steps left."""    if steps <= 0:        return 0.0    return float(-(1.0 - gamma**steps) / (1.0 - gamma))

def q_value(steps_left: int, gamma: float = 0.90) -> float:    """One -1 step plus gamma times remaining value."""    return float(-1.0 + gamma * remaining_value(steps_left, gamma))

print(round(remaining_value(6), 4))  # -> -4.6856print(round(remaining_value(8), 4))  # -> -5.6953print(round(q_value(6), 3))  # -> -5.217print(round(q_value(8), 3))  # -> -6.126

Outputs match the hand math, and the larger Q picks north.

Watch Out For

Swapping sparse reward for straight line distance

Dense −∥s−g∥-\lVert s - g \rVert looks helpful but punishes detours. Behind a U wall the shortest Euclidean step pushes into the barrier while the true path first moves away. The symptom is a policy stuck pressing the wall.

Stay sparse with −1-1 plus hindsight relabeling. If shaping is needed, learn a reachability distance rather than raw Cartesian gap.

The Quick Version

  • Policy and values take (s,g)(s, g), so one net serves many destinations.
  • UVFA builds are joint MLP or factored dot product of state and goal codes.
  • Sparse 00 versus −1-1 encodes shortest discounted path without wall traps.
  • At gamma 0.9, north gives Q minus 5.22 and south gives minus 6.13, so north wins.
  • Failed runs relabel to reached goals, which powers hindsight replay.