Exploration by Skills and Goals (UC Berkeley CS 285)

Four skills start as the same random walk. A discriminator pays each skill for states that only it visits. In 40 rounds the information between skill and state climbs from 0 to 1.99 bits, near the 2-bit limit for four skills.

Press Run and watch each colour claim its own part of the room. Then pick Goals, drag α to −1 and press Run again: Skew-Fit spreads its practice goals over all 72 free cells, where plain fitting reaches 26. Then we build it piece by piece: bonuses, entropy, skills, goals and goal proposals.

You need the DIAYN reward from Hierarchical Policies and goal-conditioned RL from Multi-Task and Goal-Conditioned RL. We build the rest here.

A supplement to UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine. Sources: Lecture 23 (exploration and skill learning), Lecture 19 (exploration) and Lecture 24 (page 38). The words, toys and numbers are our own.

Grow skills, then spread goals

Illustrative toy. Skills: a 9×9 room, 5 moves, 8 steps from the centre. Each round solves each skill's policy exactly by soft value iteration on the reward log₂ q(z|s) − log₂ p(z). Then q moves 10% of the way to the true posterior. Goals: a room with a 3×3 block, 20 goals per round, 2 random steps after each goal.

Chapter 0

Why Exploration Needs More Than Reward

See which problems we can explore well, what a novelty bonus does, and the other answer: practise without any reward

Montezuma's Revenge pays for a key and for a door. Between them lie hundreds of steps that pay nothing, and a skull that ends a life with no signal. A random agent almost never reaches the key, so it never learns that keys matter.

Exploration is choosing actions to learn about the world, not to collect reward now. The course states it two ways and calls them one problem. Find a long chain of unrewarded steps that leads to reward. Decide when to try something new instead of the best thing you know.

ProblemCan we explore optimally?
Multi-armed banditYes. It is a POMDP whose hidden state is each arm's payoff rate θ.
Contextual banditYes, by the same POMDP view.
Small tabular MDPIn theory: identify the model and price each piece of information.
Large MDPNo. Borrow ideas from the small cases and use practical tricks.

Solving the bandit's POMDP over beliefs about θ gives the best strategy, but the belief is huge. A cheaper rule does well: pay a bonus for states the agent has seen rarely. Call the visit count of state s N(s).

r+(s, a) = r(s, a) + B(N(s))
Say it aloud

r-plus of s and a equals r of s and a, plus B of N of s.

r+(s, a)
r-plus of s and a the reward the agent trains on.
r(s, a)
r of s and a the environment's reward. In Montezuma it is 0 almost everywhere.
B
B the bonus function. It falls as the count grows.
N(s)
N of s how many times the agent has visited state s.
In plain words

Count the visits N(s) to the state. Turn the count into a bonus with B. Add it to the reward r, and train any RL method on r-plus.

With numbers

With made-up numbers: a corridor cell with r = 0, seen 4 times, and B = 1/√N. The bonus is 0.5, so r+ = 0.5. After 100 visits it is 0.1.

Compare three bonus shapes

Each curve is a bonus against the visit count N. Drag N to read the three bonuses. Drag n, the total visits so far, to move UCB.

4
100

The course lists these three shapes: UCB √(2 ln n / N), MBIE-EB √(1/N) (Strehl and Littman, 2008) and BEB 1/N (Kolter and Ng, 2009). Bellemare and colleagues used MBIE-EB in 2016. The curves are exact; no agent runs here.

The course's advice: many functions work, as long as they fall with N. They differ in how fast the bonus fades. The failure is a wrong bonus weight: the agent keeps chasing novelty and never cashes in. Plot the environment return apart from the bonus; if it stays flat while coverage grows, lower the weight. Counts on images need pseudo-counts or RND, taught in Exploration.

There is a second answer. A robot in a messy kitchen practises with no task at all. Later someone asks it to do the dishes, and it already has the pieces. The rest of this lesson builds that idea with information theory.

  1. Coverage and control: entropy and empowerment, in bits.
  2. Skills: DIAYN as the information between skill and state (the hero's Skills tab).
  3. Goals: goal reaching as I(g; s), and why goals are not tasks.
  4. Goal proposals: Skew-Fit (the hero's Goals tab), Go-Explore and HOMER.
  5. The field guide: equations, numbers, code, links and the credit.
Why does a random agent fail in Montezuma's Revenge?

Chapter 1

Coverage and Control, Measured in Bits

Score how much of the room a policy visits, and how much its actions decide where it goes next

A robot that never leaves its charger learns nothing about the room. We need a number for how much of the room it visits, and one for how much it decides where it goes. Logs are base 2, so each quantity is in bits.

The state marginal π(s) is the share of time a policy spends in state s. Its entropy is the average of minus log π(s): the number of yes-or-no questions you need, on average, to name the state.

H(π(s)) = −Σs π(s) log₂ π(s)
Say it aloud

H of pi of s equals minus the sum over s of pi of s times log two of pi of s.

H(π(s))
H of pi of s the state-marginal entropy: the course's measure of coverage.
Σs
the sum over s one term for each of the 81 cells.
π(s)
pi of s the share of time the policy spends in cell s.
log₂ π(s)
log two of pi of s below 0, and far below 0 for a rare cell.
In plain words

Multiply each cell's share π(s) by its log. Add over the cells and flip the sign. An even spread gives a large H; one cell gives 0.

With numbers

Our room has 81 cells. A policy that stays home has H = 0. An even spread gives log₂ 81 = 6.34 bits. An 8-step random walk from the centre gives 4.89 bits.

Mutual information I(x; y) is how much knowing x tells you about y. It is the entropy of y minus the entropy left once you know x. The course's control example is empowerment (Polani and colleagues): the information between the action at and the next state st+1.

I(at; st+1) = H(st+1) − H(st+1 | at)
Say it aloud

I of a-t and s-t-plus-one equals H of s-t-plus-one minus H of s-t-plus-one given a-t.

I(at; st+1)
I of a-t and s-t-plus-one the bits of the next state the action decides. Empowerment uses the action mix that makes it largest.
H(st+1)
H of s-t-plus-one how spread out the next state is.
H(st+1 | at)
H of s-t-plus-one given a-t the spread that is left once you know the action: the noise.
In plain words

Measure how spread out the next state is, H(st+1). Subtract the spread that stays when you know the action, H(st+1 | at). What is left is the part of the future the action controls.

With numbers

On open floor, 5 actions reach 5 cells: H(st+1) = log₂ 5 = 2.32 bits and H(st+1 | at) = 0, so I = 2.32 bits. If a random action replaces half the chosen ones, the chosen cell comes with chance 0.6 and each other cell with 0.1. Then H(st+1 | at) = 1.77 bits, and I = 0.55 bits.

Measure coverage and control

Left: pick a policy. Right: place the agent and add noise. Bars show the chance of each next cell.

Policy (coverage)

Agent's place (control)

0.00

Illustrative toy. With noise ρ, the agent takes a uniformly random action instead, with chance ρ. Empowerment is the best I over action mixes, found with the Blahut-Arimoto method. "4 skills" is the hero's DIAYN run after 60 rounds.

The failure: reward H(st+1) alone and the agent seeks noise, which spreads the next state. Measure H(st+1 | at) too and reward the difference. At noise 1, I drops to 0.

Half of the agent's actions are replaced by random ones. What happens to empowerment?

Chapter 2

Skills a Discriminator Can Tell Apart

Read DIAYN as raising the information between skill and state, and prove its reward is a lower bound

Draw a skill number z from a prior p(z) and run the policy π(a | s, z). Hierarchical Policies gives the DIAYN reward, log q(z | s) − log p(z). The discriminator q guesses the skill from the state. Why does this reward push skills into different regions?

I(z; s) = H(z) − H(z | s)
Say it aloud

I of z and s equals H of z minus H of z given s.

I(z; s)
I of z and s the bits a state tells you about which skill is running.
H(z)
H of z how unsure you are of the skill before you look. A uniform p(z) over K skills gives log₂ K.
H(z | s)
H of z given s how unsure you stay after you see the state. It is 0 if every state belongs to one skill.
In plain words

Start with the doubt about the skill, H(z). Subtract the doubt left after seeing the state, H(z | s). A large I(z; s) means the state names the skill.

With numbers

With K = 4 uniform skills, H(z) = 2 bits. If each skill keeps to its own region, H(z | s) = 0 and I = 2 bits. If all four share one region, H(z | s) = 2 bits and I = 0.

Each term has its own lever. A uniform p(z) makes H(z) as large as it can be. The discriminator reward pushes H(z | s) down, as a split of log q shows.

E[log q(z|s) − log p(z)] = I(z; s) − Es[KL(p(z|s) ‖ q(z|s))]
Say it aloud

The average of log q of z given s minus log p of z equals I of z and s, minus the average over s of the KL from p of z given s to q of z given s.

E[log q(z|s) − log p(z)]
the average DIAYN reward over skills and the states they visit.
I(z; s)
I of z and s the information from the equation above.
Es[KL(p(z|s) ‖ q(z|s))]
the average KL from p of z given s to q of z given s how far the discriminator is from the true posterior. It is never negative.
In plain words

The true-posterior part of the reward averages to I(z; s). The rest averages to a KL, which is 0 or more. So the average reward is a lower bound on I(z; s). It equals I when q matches the true posterior.

With numbers

One state, 4 skills, q = 0.9 for the running skill: log₂ 0.9 − log₂ 0.25 = 1.85 bits. Hierarchical Policies gives 1.28: the same value in nats. A state where q = 0.25 pays 0: it tells nothing about the skill.

Pull four skills apart

Each dot is a state one skill visits. The tint is the discriminator's guess. Drag the separation, then switch to a blurry discriminator.

0.50

Illustrative toy. Each skill's states are a bell of width 0.1 on a unit square, centred along a diagonal. The exact q is the true posterior; the blurry q assumes width 0.25. All sums run on a 60×60 grid.

The failure: let p(z) drift from uniform and the ceiling drops. With p(z) = (0.7, 0.1, 0.1, 0.1), H(z) = 1.36 bits, so no policy reaches 2 bits. Log how often you draw each skill, and keep p(z) fixed and uniform. A shared start also costs bits: in the hero, 6 skills top out at 2.47 of 2.58.

Why is the average DIAYN reward never above I(z; s)?

Chapter 3

Goals Instead of Skills

Swap the skill number for a goal state, and see which term the policy controls and which the goal proposer controls

Replace the skill number z with a goal g, a state to reach. The diagram stays the same: the policy π(a | s, g) acts, and a model predicts the goal from the state reached. The reward log p(g | s) turns goal reaching into raising the information between goal and state.

I(g; s) = H(g) − H(g | s)
Say it aloud

I of g and s equals H of g minus H of g given s.

I(g; s)
I of g and s the bits the final state tells you about the goal.
H(g)
H of g how varied the proposed goals are. The goal proposer controls it.
H(g | s)
H of g given s how unsure you stay about the goal after you see where the agent ended. The policy controls it.
In plain words

Propose varied goals to raise H(g). Reach each one precisely to lower H(g | s). In practice the reward is 1 when the state lands within ε of g, which pushes H(g | s) down in the same way.

With numbers

A room of 64 cells. Propose 16 goals, one per 2×2 block, and let the policy land anywhere in its goal's block: H(g) = 4 bits, H(g | s) = 0, so I = 4 bits. Propose all 64 cells with the same policy: H(g) = 6, H(g | s) = 2, and I is still 4 bits.

Propose goals, then reach them

Teal dots are the goals. Each shaded block is where the policy may land for the goals inside it. Change both and watch which term moves.

Goals proposed (H(g))

Policy precision (H(g | s))

Illustrative toy. Goals are uniform over the proposed set. The policy lands uniformly in the aligned block that holds its goal. All entropies are exact.

The cap on I is whichever term is worse. Many goals do not help a sloppy policy; a precise policy does not help a proposer with one goal. The course points at H(g) as "often where a lot of interesting stuff happens". Chapter 4 is about it.

The failure: goals cannot say everything. "Reach the cup while staying out of the red zone" is a task, but no single goal state encodes it. The course's example is an ant that must reach a green goal and avoid a red region. Check each test task: can one target state express it? If not, use skills or a reward, not goals.

TaskA goal state?
Reach the cupYes: g is the cup's place.
Reach the cup, avoid the red zoneNo: the path matters, not only the end.
Run in circlesNo: there is no end state.
The policy lands anywhere in a 4×4 block. Going from 4 goals to 64 goals changes I(g; s) how?

Chapter 4

Propose Goals at the Edge of What You Know

Skew a goal model toward rare states so its entropy grows, and meet two other ways to push the frontier

Where do practice goals come from? Skew-Fit (Dalal, Pong, Lin, Nair, Bahl and Levine, 2019) keeps a model pψ(g) of the states the agent has reached, and loops:

  1. Propose a goal g from pψ(g).
  2. Try to reach it with π(a | s, g).
  3. Use the data to update π.
  4. Use the data to update pψ(g).

A plain fit copies the data, so it proposes goals where the agent already goes. Skew-Fit weights each sample in the fit by its own density, raised to a negative power α.

w(g) = pψ(g)α,   α ∈ [−1, 0)
Say it aloud

w of g equals p-psi of g to the power alpha, with alpha from minus one up to, but not including, zero.

w(g)
w of g the weight of sample g in the next weighted maximum-likelihood fit.
pψ(g)
p-psi of g the current goal model's density at g: high for common states, low for rare ones.
α
alpha the skew. 0 is a plain fit; −1 weights each sample by one over its density.
In plain words

Give each reached state the weight w(g), so rare states count more. Fit the new pψ to the weighted data. For a table of shares, the new share of g is pψ(g) to the power 1 + α, rescaled to sum to 1.

With numbers

With made-up shares 0.7, 0.2 and 0.1 and α = −0.5: take square roots, 0.837, 0.447 and 0.316, and rescale to 0.523, 0.279 and 0.198. The entropy rises from 1.16 to 1.47 bits. At α = −1 all shares become 1/3: 1.58 bits.

Skew six goal shares

Grey bars are the plain fit, from states near the start. Teal bars are the skewed fit. Drag α below 0, then above it.

−0.50

Illustrative shares 0.40, 0.25, 0.15, 0.10, 0.06 and 0.04. Positive α is outside Skew-Fit's range; it is here to show the opposite effect.

The course states the key result: for any α in [−1, 0), the entropy H(pψ(g)) increases. In the hero, α = −1 reaches all 72 free cells in 40 rounds; α = 0 reaches 26.

The failure: at α = −1 the rarest share, 0.04, gets weight 25, and the commonest, 0.40, gets 2.5. If a rare density is a model error, the loop chases noise. Log the largest normalised weight. The fix is α nearer 0, or a cap on the weights. Skew-Fit also spreads goals over every reachable state, useful or not.

MethodHow it pushes the frontier
Skew-FitFits a goal model that favours rare states, then practises reaching them.
Go-Explore (Ecoffet and colleagues)Keeps an archive of cells; picks one, returns to it by restoring the simulator or with a goal-conditioned policy, explores from there, adds new cells.
HOMER (Misra and colleagues)Alternates exploring and learning a small abstract state map, growing the explored part of the MDP.
What does Skew-Fit's weight w(g) = pψ(g)α with α = −1 do to the goal model?

Chapter 5

The Field Guide

Keep the equations, the numbers, a checklist and the core code on one page, and see where to go next

Bonuses pay for novelty and fade with counts. Without any reward, information theory gives targets: coverage is state entropy, control is empowerment. DIAYN raises I(z; s), with a uniform prior for H(z) and a discriminator reward that lower-bounds I. Goals swap z for g, so the policy lowers H(g | s) and the proposer raises H(g). Skew-Fit raises H(g) by weighting rare states up.

The equations

IdeaFormChapter
Count bonusr+ = r + B(N(s)); B = √(2 ln n/N), √(1/N) or 1/N0
CoverageH(π(s)) = −Σ π(s) log₂ π(s)1
EmpowermentI(at; st+1) = H(st+1) − H(st+1 | at)1
SkillsI(z; s) = H(z) − H(z | s)2
DIAYN boundE[log q − log p(z)] = I(z; s) − E KL(p(z|s) ‖ q) ≤ I(z; s)2
GoalsI(g; s) = H(g) − H(g | s)3
Skew-Fitw(g) = pψ(g)α, α ∈ [−1, 0); new shares ∝ p1+α4

The numbers from our toys

WhatNumberWhy it matters
Bonuses at N = 4, n = 100UCB 1.52, MBIE-EB 0.50, BEB 0.25Same idea, different fade
Coverage of the 81-cell room0 at home; 4.89 random walk; 6.34 at mostEntropy counts places
Empowerment, open floor2.32 bits; 0.55 with noise 0.5Noise spreads the future but removes control
DIAYN, 4 skills, 40 roundsI = 1.99 of 2.00 bitsThe skills split the room
Skewed prior (0.7, 0.1, 0.1, 0.1)H(z) = 1.36 bits, not 2Keep p(z) uniform
64 goals, 2×2 precisionI = 6 − 2 = 4 bitsPrecision caps the gain from goals
Skew-Fit, 40 rounds72 of 72 cells at α = −1; 26 at α = 0Rare goals push the frontier

Checklist

  1. With a sparse reward, plot the environment return apart from any bonus.
  2. For skills, fix p(z) uniform and log the frequency of each sampled skill.
  3. Log the average discriminator reward. It is a lower bound on I(z; s), not I itself.
  4. Let the discriminator see only the features that matter, such as position.
  5. For goals, check that each test task is a goal state. If not, use skills or a reward.
  6. With Skew-Fit, log the goal entropy and the largest normalised weight.

The core code

pythonimport numpy as np

def diayn_reward(q_probs, z, K):
    # q_probs: (B, K) discriminator softmax at the visited states; z: (B,) skill ids
    return np.log2(q_probs[np.arange(len(z)), z]) - np.log2(1.0 / K)   # bits

def skew_weights(density, alpha=-1.0):
    # density: (B,) p_psi at each reached state; alpha in [-1, 0)
    w = density ** alpha
    return w / w.sum()                    # weights for the next weighted MLE fit

def entropy_bits(p):
    p = p[p > 0]
    return -(p * np.log2(p)).sum()

# skills: draw z uniform, roll pi(a|s,z), train pi with SAC on diayn_reward, train q to classify z from s
# goals:  g ~ p_psi, roll pi(a|s,g), train pi; refit p_psi with skew_weights

Keep going

The takeaway. Without a reward, aim for information. Skills raise I(z; s), goals raise I(g; s), and the hard part is proposing goals that keep the frontier moving.
In goal reaching as I(g; s) = H(g) − H(g | s), which term does Skew-Fit raise?

Now press Present or Teach and explain from memory: the bonus shapes, coverage and empowerment, why the DIAYN reward lower-bounds I(z; s), the two terms of I(g; s), and the Skew-Fit weight. Then go back to the hero, train the skills, and spread the goals.

Credit and source

This lesson supplements UC Berkeley CS 185/285, Deep Reinforcement Learning, Sergey Levine, at rail.eecs.berkeley.edu/deeprlcourse. It draws on Lecture 23 (pages 2 to 18), Lecture 19 (pages 3 to 19) and Lecture 24 (page 38). The papers are Eysenbach, Gupta, Ibarz and Levine, Diversity is All You Need (2018); Dalal, Pong, Lin, Nair, Bahl and Levine, Skew-Fit (2019); and Ecoffet and colleagues, Go-Explore (2019). The words, toys and numbers here are our own.

Exploration by Skills and Goals (UC Berkeley CS 285)
The course site · Lecture 23 PDF · Lecture 19 PDF · Back to Gleams