Visual walkthrough — Deep Q-Networks (DQN)
The result we are marching toward:
Every letter in there is a promise. Let us earn each one.
Step 1 — What is a "state", an "action", and a "reward"?
WHAT. Picture an agent (a little robot) standing in a world. At each tick of the clock it sees a state (everything it can observe right now — a game screen, a position), chooses an action (press a button, step left), and the world hands back a reward (a number: +1 good, −1 bad, 0 nothing) and drops it into a new state .
WHY these three. They are the only things the agent ever touches. Learning = discovering which in which leads to the most reward over time. Everything else is bookkeeping.
PICTURE. The loop below is the whole game: state → action → reward + next state → repeat.

Step 2 — Why we want ONE number per (state, action): the value
WHAT. We invent a scorekeeper called ==== — a single number meaning "how much total reward do I expect if I take action here, and play well forever after?" Big = promising move.
WHY a total, not just the next reward. A move that gives now but sets up a jackpot later must still look good. So must look into the future, not just the next step.
WHY "discounted". A reward now is worth more than the same reward in 100 turns (it's more certain, more useful). We shrink far-off rewards by a factor ==== (gamma, between 0 and 1) raised to how many steps away they are: — a decaying staircase.
PICTURE. Future rewards stacked up, each shorter than the last because shrinks.

- — reward received this turn, full weight ().
- — next turn's reward, worth a fraction .
- the "" — the infinite tail, each term smaller than the last. Because the total is a finite number even though the sum never ends.
This is the Q-Learning value; see also Temporal Difference Learning for the update flavour.
Step 3 — The recursion trick: fold the infinite tail into itself
WHAT. We split the giant sum into two pieces: the first reward, and everything after.
WHY. Look inside the bracket — it is itself a -shaped sum, but starting one step later, from the next state . So the tail equals the value of . We just discovered the future is a smaller copy of the present. That self-reference is the recursion that makes learning possible.
WHY "max". From we get to choose again — and to play optimally we pick the best next action . "Best" means the largest , written ====: scan every possible next action, keep the biggest score.
PICTURE. A tree: the current move, then the fan of next actions from ; the thick branch is the (the one we'd actually take).

Step 4 — Why we can't just USE this equation (enter the neural net)
WHAT. Bellman defines but doesn't hand it to us — the right side contains itself, the very thing we don't know. And there are far too many states to store one number each (think every possible game screen).
WHY a network. Instead of a lookup table we use a neural network : a machine with tunable knobs ==== (theta, the weights) that eats a state and guesses a value for each action. Similar states → similar guesses, so it generalises — learning about one screen teaches it about lookalike screens.
PICTURE. Left: an impossibly tall table (impossible). Right: a compact net turning a state into action-scores.

- — the adjustable weights. "Training" = nudging so the guesses get right.
- The net outputs one number per discrete action. (This is exactly why DQN needs discrete actions — you can't list a over a continuous knob.)
Step 5 — Bootstrapping: build a target out of our own guess
WHAT. We can't compare our guess to the true (unknown). So we compare it to the best estimate we can assemble right now from real data: the reward we actually saw, plus our own discounted guess of the next state's value. Call this the ==target ==:
WHY it's legitimate. Half of is ground truth ( really happened). Only the tail is a guess. Each update makes a little truer, which makes the next truer — the guess pulls itself up by its bootstraps. This is bootstrapping.
WHY and not . The knobs used inside are a frozen copy ==== (the target network idea's ancestor). If used the same live we are editing, the target would jump the instant we take a step — a dog chasing its own tail. Freezing it gives a steady thing to aim at. We refresh only every steps.
PICTURE. Two networks: the live one we train (blue), and its frozen older twin (yellow) that builds the target.

Step 6 — The TD error and the loss: measuring the gap
WHAT. The TD error (, delta) is simply target minus current guess:
If our net underestimated — push up. If it overestimated — push down. If , Bellman is satisfied here; leave it.
WHY square it. We want any gap punished (sign shouldn't matter) and big gaps punished more. Squaring does both and is smooth to differentiate:
WHY freeze during the gradient. We differentiate w.r.t. but treat
as a constant label (stop-gradient). It contains , not , so there's
nothing live to differentiate anyway — and pretending otherwise makes training diverge.
PICTURE. A parabola : gradient descent slides the guess toward at the bottom.

- — step size (learning rate); how far each nudge goes.
- — the direction in knob-space that raises ; multiply by to move the right way by the right amount.
Step 7 — The degenerate case: a terminal state
WHAT. When is terminal (the episode ended — game over, goal reached), there is no next state to evaluate. So the future term vanishes and the target collapses to just the reward:
WHY. asks "value of the best move from " — but from a finished game there are no moves and no future reward. Keeping the term would invent phantom future value and bias every estimate upward. Dropping it is not optional; it's the boundary condition of the recursion.
PICTURE. Two paths side by side: non-terminal (future tail present) vs terminal (tail cut off).

Step 8 — Two worked targets, drawn on the number line
Non-terminal — , , target net gives , ; current .
Positive → net underestimates → push up toward .
Terminal — same numbers but is terminal, and old .
Negative → nudge down.
PICTURE. Both targets and current guesses plotted on one axis; arrows show which way moves.

The one-picture summary
Everything on this page compressed: the game loop feeds transitions into the replay buffer; a random batch is drawn; the frozen twin builds the target ; we compare to the live guess, get , and slide the knobs downhill on . Every steps the twin is refreshed.

Recall Feynman retelling — the whole walkthrough in plain words
A robot plays a game and writes down each moment as (what I saw, what I did, the points I got, what I saw next). It wants a scorekeeper that, given a screen and a button, guesses the total future points. That total is a shrinking sum of rewards — and cleverly, the future is just a smaller copy of the present (recursion), so the score = points now + a shrunk copy of "the best I can do next". Since it doesn't know the true best, it uses its own guess as a stand-in (bootstrapping), but reads that guess off a frozen older twin so the target doesn't wobble. It measures how wrong the guess is (the TD gap), squares it so both over- and under-guesses hurt, and nudges its knobs downhill. When the game ends there's no "next", so the score is just the last reward. Repeat millions of times and the guesser becomes a champion.
Connections
- Deep Q-Networks (DQN) — the parent note this page zooms into.
- Bellman Equation — Steps 3 provides its picture.
- Q-Learning — the tabular version of Steps 2–3.
- Temporal Difference Learning — Step 6's is the TD error.
- Experience Replay — where the batches in the summary come from.
- Double DQN — refines the frozen-twin of Step 5.
- Dueling DQN — an alternative network shape for Step 4.
- Epsilon-Greedy Exploration — how actions in Step 1 are actually chosen.
- Policy Gradient Methods — the sibling family that skips entirely.