5.2.2 · D1Deep & Advanced RL

Foundations — Experience replay

2,550 words12 min readBack to topic

This is the ground-floor page for Experience replay. Nothing here assumes you have seen reinforcement learning before. Every letter and squiggle the parent note uses is defined below, in an order where each idea rests on the one above it.


1. The agent, the world, and one "moment"

Picture a little robot playing a game. At every tick of the clock, four things happen. Let us name them.

Figure — Experience replay

Bundle those four into one packet:


2. Counting and averaging: the tools behind the buffer

Why does "almost identical neighbours" matter? Because 3 pixels of movement between and barely changes the screen.

Figure — Experience replay

3. Value: teaching a number to a picture

Now the heart of it: what is the network actually learning?

Figure — Experience replay

Now we can state the equation the whole target is built on.


4. The whole picture as a prerequisite map

state s

transition e = s a r s prime

action a

reward r

next state s prime

buffer D of N transitions

uniform random sample B

approx i.i.d. batch

value Q with knobs theta

Bellman optimality equation

discount gamma and max over a prime

bootstrapped target y with done flag d

TD error delta

squared loss

EXPERIENCE REPLAY update

Read it top-down: the four raw items form a transition, transitions fill the buffer, random sampling makes an almost-i.i.d. batch; meanwhile the value network and the discounted Bellman rule build a target (with the terminal switch), the gap becomes a squared loss — and averaging that loss over the random batch is experience replay.


5. Two flavours of learning (why replay is even allowed)


Equipment checklist

Cover the right side; can you say each before revealing?

What the four items of a transition are
state , action , reward , next state (= )
What and mean
is the whole FIFO buffer; is how many transitions it holds
What says out loud
"take a mini-batch by picking transitions from each with equal probability"
Why we want i.i.d. samples
neural-net training assumes samples are independent and from one source; correlated live streams break that
What and do
adds up; the version is the plain average over the batch
What predicts
the expected total (discounted) future reward for doing in state , given knob settings
What the Bellman optimality equation says
— true value = reward + discounted best future value
What and do in the target
shrinks future reward; picks the best possible next action's value
What and are
is the bootstrapped target ("should-have-been" score); is a frozen old copy of the network used to build it
How a terminal next state changes
with done flag the factor kills the bootstrap, so (no future value)
What and the squared loss are
is the gap; the loss is , punishing big misses hardest
Why replay suits off-policy but not on-policy
the buffer holds old-policy data; only off-policy methods can learn from data made by a different/older policy