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.
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
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.
| Problem | Can we explore optimally? |
|---|---|
| Multi-armed bandit | Yes. It is a POMDP whose hidden state is each arm's payoff rate θ. |
| Contextual bandit | Yes, by the same POMDP view. |
| Small tabular MDP | In theory: identify the model and price each piece of information. |
| Large MDP | No. 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-plus of s and a equals r of s and a, plus B of N of s.
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 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.
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.
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.
Chapter 1
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 of pi of s equals minus the sum over s of pi of s times log two of pi of s.
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.
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 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.
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.
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.
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)
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.
Chapter 2
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 of z and s equals H of z minus H of z given s.
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 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.
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.
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.
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.
Each dot is a state one skill visits. The tint is the discriminator's guess. Drag the separation, then switch to a blurry discriminator.
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.
Chapter 3
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 of g and s equals H of g minus H of g given s.
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.
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.
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.
| Task | A goal state? |
|---|---|
| Reach the cup | Yes: g is the cup's place. |
| Reach the cup, avoid the red zone | No: the path matters, not only the end. |
| Run in circles | No: there is no end state. |
Chapter 4
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:
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 of g equals p-psi of g to the power alpha, with alpha from minus one up to, but not including, zero.
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 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.
Grey bars are the plain fit, from states near the start. Teal bars are the skewed fit. Drag α below 0, then above it.
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.
| Method | How it pushes the frontier |
|---|---|
| Skew-Fit | Fits 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. |
Chapter 5
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.
| Idea | Form | Chapter |
|---|---|---|
| Count bonus | r+ = r + B(N(s)); B = √(2 ln n/N), √(1/N) or 1/N | 0 |
| Coverage | H(π(s)) = −Σ π(s) log₂ π(s) | 1 |
| Empowerment | I(at; st+1) = H(st+1) − H(st+1 | at) | 1 |
| Skills | I(z; s) = H(z) − H(z | s) | 2 |
| DIAYN bound | E[log q − log p(z)] = I(z; s) − E KL(p(z|s) ‖ q) ≤ I(z; s) | 2 |
| Goals | I(g; s) = H(g) − H(g | s) | 3 |
| Skew-Fit | w(g) = pψ(g)α, α ∈ [−1, 0); new shares ∝ p1+α | 4 |
| What | Number | Why it matters |
|---|---|---|
| Bonuses at N = 4, n = 100 | UCB 1.52, MBIE-EB 0.50, BEB 0.25 | Same idea, different fade |
| Coverage of the 81-cell room | 0 at home; 4.89 random walk; 6.34 at most | Entropy counts places |
| Empowerment, open floor | 2.32 bits; 0.55 with noise 0.5 | Noise spreads the future but removes control |
| DIAYN, 4 skills, 40 rounds | I = 1.99 of 2.00 bits | The skills split the room |
| Skewed prior (0.7, 0.1, 0.1, 0.1) | H(z) = 1.36 bits, not 2 | Keep p(z) uniform |
| 64 goals, 2×2 precision | I = 6 − 2 = 4 bits | Precision caps the gain from goals |
| Skew-Fit, 40 rounds | 72 of 72 cells at α = −1; 26 at α = 0 | Rare goals push the frontier |
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
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.
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.