Drawing from a hat of noise
Before Ganesh Chaturthi, a sculptor in a small workshop makes one idol after another. Every morning his helper hands him a lump of clay. No two lumps are the same: one is a little bigger, one a little lopsided, one a little wetter.
The sculptor's hands make the same moves every time. Yet every idol comes out slightly different, and every one of them still looks like Ganesha. The skill is fixed. The lump is random. Put the two together and new idols keep coming.
The question. How can a machine draw a face that has never existed?
Here is the whole idea of this unit in one line: to create is to sample. A machine that creates is a machine that takes easy randomness — the lump of clay — and turns it into something that looks like the real data. We call such a machine a generator. The randomness goes in, the sculptor's fixed skill is a function , and a new example comes out: .
By hand, with heights. Say the heights of grown men in a town follow a bell curve with mean 170 cm and spread 7 cm, written . How do we make up a new, realistic height? Draw a standard random number from — the easiest bell curve there is, centred at 0 with spread 1 — and then stretch and shift it:
Four draws of the hat give . The machine turns them into
Four new men who never existed, each with a believable height. The skill (, then ) never changed. Only the lump did.
Not every shape is a bell. Waiting times at a bus stop, say, follow an exponential curve: short waits are common and long waits are rare. With the chance that the wait is at most minutes is . Now take the plainest noise of all, a number spread evenly between 0 and 1, and solve for :
With : minutes. This trick is called the inverse CDF (the CDF is the "chance of at most " curve, ). It works for any shape of data in one dimension: run the curve backwards on even noise.
The hard part. For heights and waiting times someone can write the curve down. For pictures, nobody can. A 20 × 20 grey picture is already 400 numbers, and there is no formula for "all the pictures that look like a face". So the generator has to be learned from examples. That is what the whole unit is about: two ways to learn the sculptor's hands — the VAE (Act II) and diffusion (Act III).
Look at the curve as a funnel. Where it is steep, a narrow band of inputs is stretched over a wide band of outputs, so the balls spread thin. Where it is flat, a wide band of inputs is squeezed into a narrow band of outputs, so the balls pile up. So the curve decides where the pile is high and where it is low: output density = input density ÷ slope. The inverse CDF picks exactly the curve whose slope makes the pile come out right. A learned generator does the same thing in hundreds of dimensions, with a neural network as the curve.
Four ways to learn the sculptor's hands. Every modern generator turns noise into data. They differ in how the noise goes in and how the machine is trained.
| family | how it draws | where the noise goes in | good at | weak at |
|---|---|---|---|---|
| autoregressive (Unit 19) | one piece at a time, each piece chosen from a probability list | a dice roll at every token | text; exact likelihood | slow: one step per piece |
| VAE (§3–§7) | pick a point on a small map, decode it in one go | the point | fast; a smooth map you can walk | blurry pictures |
| GAN | one pass of a generator network | a random vector | sharp pictures, fast | unstable training; can forget whole kinds of data |
| diffusion (§8–§13) | start from static, remove a little noise many times | the starting static, and a little at every step | sharp, varied pictures; easy to steer | many steps (§12 makes it faster) |
A GAN in one paragraph. A GAN (a generative adversarial network) trains two networks against each other, like a forger and a detective. The forger turns noise into fake pictures. The detective looks at real pictures and fakes and says "real" or "fake". The forger improves by fooling the detective, the detective improves by catching the forger. It gives sharp pictures, but the contest is hard to balance, and the forger may learn to draw only a few kinds of picture that fool the detective. We will not build one here: the VAE and diffusion are the ones whose maths this course has prepared you for.
Rule of thumb. Text: autoregressive. A fast generator with a smooth map of the data: VAE. The best pictures today: diffusion — often run inside a VAE's map (§13).
A machine that hands back the training pictures is not creating — it is copying. We want new examples that come from the same distribution as the training data: new heights that are believable, not the heights of the men we measured. A generator is judged by whether its samples look like they came from the same hat, not by whether they match any one example.
A generator is a fixed function applied to fresh noise. In one dimension we can write the function down: stretch-and-shift for a bell curve, the inverse CDF for anything else. For pictures the function must be learned — and learning it is the whole art.
In the heights machine you change the curve from to . What happens to the green pile of outputs?
In the waiting-times machine , where do most of the outputs pile up, and why?
If you want the algebra · 2 proofs, step by step
Claim. Let be a CDF that rises steadily (so it has an inverse), and let be spread evenly on . Then has exactly the CDF .
Claim. If with increasing, and has density , then has density at .
The road ahead. The unit has four acts.
- To create is to sample (§1–§2): the noise machine, and the two facts about Gaussian noise that everything later uses.
- Squeeze, then rebuild (§3–§7): the autoencoder, the VAE's cloud, the reparameterisation trick, the ELBO, and walking the map of faces.
- Noise in, noise out (§8–§12): diffusion — destroy a picture with noise, learn to guess the noise, the score as a compass, walk back from static, and the fast jump.
- Steering, and the whole course (§13–§14): steering with words, latent diffusion, and every tool of the course inside the two machines.
In one sentence: A generator is a sculptor's fixed skill applied to a random lump of clay — with fresh noise — and since nobody can write down for pictures, the machine has to learn it.
The Gaussian toolkit for noise
You have a glass of hot chai, filled to the brim. You pour out one tenth of it and top the glass up with milk. Then you do it again, and again. The glass is always exactly full. But after enough rounds, what is in it is almost all milk, and it no longer matters whether you started with strong chai or weak chai.
The question. Diffusion (Act III) will add noise to a picture again and again. How do we add noise so that the numbers never blow up, and so that we always know exactly where they end up?
Two facts about bell curves from Unit 14 do all the work.
- Scaling. Multiply a random number by and its variance is multiplied by : . (The spread, which is the square root, is multiplied by .)
- Adding. Add two independent bell curves and you get a bell curve whose variances add: .
One noising step. Take a number and fresh noise , and make
This is the chai glass: keep 90% of the variance of the old drink, top up with 10% of new milk. If itself was a standard bell curve, the two facts give the new variance at once:
The glass stays exactly full. Now fix one starting value, . The first part is no longer random: . Only the noise part is random, with spread . So
In words: shrink the signal a little, add a little noise, and the total size stays the same. Repeat it times and the signal shrinks to while the noise variance grows to . After many steps the starting point is forgotten, and every start ends in the same cloud, . This one step, repeated, is the forward process of diffusion (§8).
Because the two numbers and are chosen so that their squares add up to 1. Variance is what adds for independent noise, and a factor inside a variance comes out squared. So the step takes exactly 10% of the variance away from the signal and gives exactly 10% to fresh noise. Nothing grows, nothing shrinks overall; the drink just slowly turns into milk. Any pair and does the same, which is why diffusion writes every step this way.
Two ways to add noise, side by side.
| just add noise: | shrink, then add: | |
|---|---|---|
| variance after one step (start ) | 1.1 | 1 |
| after 100 steps | 11 — it keeps growing | still 1 |
| where every start ends up | nowhere fixed: the cloud keeps spreading | the same , whatever the start |
| used by | score models with growing noise | DDPM (§8) — "variance preserving" |
Rule of thumb. Shrink by whenever you add noise of variance . Then the numbers stay the same size forever, and the end of the road is always the same easy cloud.
Add two independent noises, each with spread 1. The spread of the sum is not 2. Variances add, spreads do not: the variance is , so the spread is . Two people pushing a cart in random directions do not push it twice as far — they often partly cancel.
For independent noise, variances add and a scale factor comes out squared. So "shrink by , add noise of variance " keeps a standard cloud standard, and slowly washes any starting point into the same .
Start from the fixed number and take two steps , with fresh noise each time. What is the bell curve now?
You add three independent noises, each with spread 2. What is the spread of the total?
If you want the algebra · 2 proofs, step by step
Claim. If and are independent, with means , then .
Claim. Start at a fixed and repeat with fresh noise. After steps, .
In one sentence: For independent noise variances add and scale factors come out squared, so "shrink by , add noise of variance " keeps the glass exactly full while slowly turning any chai into the same milk, .
The autoencoder: squeeze and rebuild
Your friend is arriving at a crowded railway station, and your cousin has never seen him. You phone your cousin, and the line is bad — you only have time for two numbers. You say: "Face size 7 out of 10. Smile 9 out of 10." Your cousin, who is good at sketching, draws a face from those two numbers and goes looking for the man who matches.
You squeezed a whole face into two numbers. Your cousin rebuilt a face from them. If the sketch looks like your friend, the two numbers held what mattered.
The question. Can a machine learn, by itself, which few numbers describe a picture — and learn to draw the picture back from them?
An autoencoder is two networks back to back. The encoder (you, on the phone) reads a picture and squeezes it into a short list of numbers, the code . The decoder (your cousin) reads the code and rebuilds a picture . Training asks only one thing: make the rebuild match the picture. The loss is the squared error over every pixel, summed over all the training pictures:
The toy on this page. We made up 4 000 small grey faces, each 20 × 20 = 400 pixels. Two things vary: how big the face is, and how much it smiles (from a frown to a big smile). We trained a small autoencoder on them for this page, with a code of just 2 numbers — so the whole map of codes fits on your screen. 400 numbers in, 2 in the middle, 400 out: a squeeze of 200 times. Nobody told the network about "size" or "smile". The squeeze forced it to find them, because two numbers are only enough if they are the two that matter.
You have seen this before. In Unit 12, PCA squeezed data onto the few directions with the most variation. Make the encoder and decoder plain matrices (no curves at all) and train with squared error: the best such autoencoder squeezes onto exactly the same subspace as PCA. A curved (nonlinear) autoencoder can do more: it can bend its map to follow data that lies on a curved surface.
So can we create? Here is the tempting idea: throw away the encoder, pick a random code, and let the decoder draw. Try it below. On the plain autoencoder it mostly fails. The codes of real faces landed in a lopsided patch, stretched far to one side of 0, with empty regions around it. Nothing in training ever asked the decoder what to draw for a code from an empty region, so it draws whatever it likes — often something that is not a face at all.
Because the squeeze leaves no room for anything else. Two numbers cannot hold 400 pixels, so the network must spend them on whatever changes most from face to face — here, size and smile. Every face that differs only in the small details gets the same code and the same rebuild. That is PCA's idea (Unit 12) done with curves: keep the few directions along which the data really varies, and throw the rest away. And it is also why the empty regions are dangerous: the loss only ever looked at the codes of real faces, so every other point of the map is untested.
Three ways to squeeze, side by side.
| PCA (Unit 12) | linear autoencoder | nonlinear autoencoder | |
|---|---|---|---|
| squeeze | project onto the top eigenvectors | a matrix | a network with curves |
| rebuild | the same eigenvectors, back | another matrix | another network |
| what it finds | the best flat subspace | the same subspace (maybe with tilted axes) | a curved surface that follows the data |
| trained by | an eigen-decomposition, in one go | gradient descent | gradient descent |
| a random code gives | a blend of eigen-pictures | a blend of eigen-pictures | anything — often garbage outside the patch |
Rule of thumb. If the data lies near a flat subspace, PCA is enough and needs no training. If it lies on a curved surface, use an autoencoder. If you want to create, a plain autoencoder is not enough: you need a map with no empty regions — the VAE of §4.
A good rebuild does not make a good generator. The plain autoencoder rebuilds its training faces very well, yet most random codes decode to rubbish. Rebuilding asks "is the decoder right at the codes of real pictures?" Creating asks "is the decoder right everywhere we might pick a code?" Those are different questions.
An autoencoder squeezes each picture into a short code and learns to rebuild it. The squeeze forces the code to keep only what varies most — with straight lines, it is PCA. But it makes no promise about the empty parts of the map, so it is a compressor, not yet a creator.
The plain autoencoder's codes lie roughly between −10 and 0 across and between −1 and 4 up. You pick 1 000 random codes from , centred at the origin. What happens?
You train a linear autoencoder (matrices only, no curves) with a 2-number code on some data, using squared error. PCA on the same data gives a top-2 plane. What does the autoencoder's decoder span?
If you want the algebra · 1 proof, step by step
Claim. Take centred data (the rows of ), a linear encoder and a linear decoder with a -number code. The smallest possible total squared error is reached when is the projection onto the top- principal directions — the same subspace PCA keeps.
In one sentence: An autoencoder squeezes a picture into a few numbers and learns to rebuild it — describing a friend's face in two numbers over a bad phone line — but its map of codes has empty regions, so a random code usually draws rubbish.
The VAE: a cloud, not a point
You tell a friend where to meet you. If you give the exact house number — "14/B, Lane 3" — and he lands on the house next door, he is lost. If you say "near the temple in Rajpur" — a neighbourhood, not a house — then anywhere in that neighbourhood is a fine answer, and he will find you.
Now imagine every friend gives a neighbourhood instead of a house number, and the town asks everyone to keep their neighbourhoods near the town centre. The neighbourhoods overlap, and there is no empty land left in town.
The question. How do we stop the map of codes from having empty regions, so that every point decodes to something sensible?
The variational autoencoder, or VAE (Kingma and Welling, 2014), makes two changes.
- A cloud, not a point. The encoder no longer outputs one code. It outputs a centre and a spread — a small bell-shaped cloud on the map. During training we pick a random point inside the cloud, and the decoder must rebuild the picture from that point. So the decoder learns to draw well over the whole cloud, not just at its centre. A neighbourhood, not a house number.
- A pull towards the centre. A second term in the loss pulls every cloud towards the standard cloud : centre 0, spread 1. It is the KL divergence of Unit 14, which measures how far one bell curve is from another. For one number of the code,
Read it aloud. : you pay for sitting far from the centre. : you pay for a spread that is not 1 — too wide or too narrow. Four clouds, by hand:
The standard cloud itself costs nothing. Moving it away costs . And look at the last one: a cloud sitting right at the centre but too sure of itself (spread 0.1) costs more than the one at . The KL does not only pull clouds in; it also keeps them from shrinking back into points.
The full loss for one picture adds the two jobs, with a weight on the pull ( is the plain VAE):
(For a code of two numbers, the KLs of the two entries simply add up.) Our toy VAEs were trained with three weights, , on the same faces.
Two forces meet. The rebuild term wants each cloud small and apart, so that the decoder can tell the faces apart. The KL term wants every cloud to be the same wide cloud at the centre. The balance is a map where clouds of similar faces overlap. Wherever two clouds overlap, the decoder was trained to draw both faces from nearby points, so it learns to draw something in between — a sensible face. Overlap everywhere means no empty land: every point of the rings has been trained on.
The weight on the pull, side by side. These are the three toy VAEs of the widget.
| (weak pull) | (the plain VAE) | (strong pull) | |
|---|---|---|---|
| clouds | tiny, almost points | small, overlapping | wide, all at the centre |
| average KL per face | about 8.0 | about 5.0 | about 1.2 (the smile number: 0) |
| rebuilds | sharp | sharp | right size, but every mouth the same blur |
| random codes | many land in holes | almost all good faces | faces, but no smiles or frowns |
Rule of thumb. Too little pull and you have a plain autoencoder with holes. Too much and the code stops carrying information — "posterior collapse". Start at and watch the KL of each code number: a number whose KL falls to 0 has stopped being used.
The KL term is not a nuisance to push to zero. A KL of exactly 0 means the cloud is the standard cloud, whatever the picture — so the code tells the decoder nothing about the picture. At this happened to the smile number: its KL is 0, and every rebuilt mouth is the same average blur. A useful code must pay some KL.
A VAE encodes each picture as a cloud, rebuilds from a random point in it, and pays a KL price — for each number of the code — for every cloud that is far from the centre or too narrow. The clouds of similar pictures overlap, the map fills up, and every point decodes to something sensible.
Two clouds for one code number: A has , ; B has , . Which pays the bigger KL?
You raise the KL weight from 1 to 30. What happens to the clouds and to the rebuilds?
A code has two numbers. Its cloud has and . What is its total KL to ?
If you want the algebra · 1 proof, step by step
Claim. , and it is 0 only at .
In one sentence: A VAE gives every picture a neighbourhood, not a house number — a small cloud on the map — and a KL price pulls every cloud towards the town centre, so the clouds overlap and every point of the map has been trained to draw a sensible picture.
The reparameterisation trick
A darts player's hand always wobbles a little. If the wobble happens by surprise, you cannot say what would have happened had he aimed a little to the left. But suppose the wobble is decided in advance — written on a card before the throw: "2 cm right, 1 cm up". Now the dart lands at aim + wobble. Move the aim 1 cm left, and the dart moves exactly 1 cm left. You can ask how the aim moves the dart.
The question. Training a VAE means backpropagation (Unit 7): blame flows from the loss back to every weight. But in the middle of the network we draw a random point from the cloud. How does blame flow backwards through a dice roll?
It cannot, as long as the dice roll is inside the network. "Draw from " is not a formula in and : nudge and the draw simply comes out different, with no slope to follow.
The trick. Roll the dice first, outside the network, as the card with the wobble: . Then build the draw by the stretch-and-shift of §1:
The randomness has moved into an input. And is now an ordinary formula in and , so it has slopes.
By hand. Take , , and the card says :
Now the chain rule of Unit 7 does the rest. Say the rest of the network (a stand-in here) gives the loss : the decoder would like to be 2. Then , and the blame splits:
Both slopes are negative, so gradient descent raises (and, with this , a little) to move the dart towards 2. Blame flows straight through.
Because with is exactly a draw from — the stretch-and-shift of §1. So nothing about the model changes; only the bookkeeping does. The randomness is now a fixed input for each training step, like a picture, and everything that depends on and is a smooth formula. Average the slopes over many wobbles and you get the true slope of the average loss.
Two ways to draw, side by side.
| dice inside: draw | reparameterised: | |
|---|---|---|
| what comes out | a draw from | a draw from — the same |
| where the randomness lives | in the middle of the network | in an input , drawn first |
| , | not defined | 1 and |
| training | needs slow, noisy tricks | ordinary backprop |
Rule of thumb. Whenever a network must sample in the middle, write the sample as "parameters + a formula of outside noise". Diffusion does the same thing in §8: .
The wobble is not learned and not optimised. It is fresh noise for every picture at every step, and it gets no slope of its own. What learns are and — and, through them, the encoder's weights.
Roll the dice before the network, not inside it. The draw is the same, but now it is a formula in and , and the chain rule carries the blame straight back to the encoder.
With , , the card says . What are and ?
You switch from "dice inside" to the reparameterised form, and draw 10 000 values of each way. How do the two histograms compare?
If you want the algebra · 1 proof, step by step
Claim. For a loss and , : and .
In one sentence: Write the random draw as with the wobble rolled in advance — a dartboard where the wobble is written on a card — and the chain rule can carry blame through the sampling step straight back to the encoder.
The ELBO: the score a VAE maximises
You want to know how high the ceiling of a hall is, but you cannot reach it. What you can measure is a platform you are standing on. The platform is always below the ceiling. Push the platform up, and one of two things must be happening: the ceiling is rising, or the gap between you and the ceiling is closing. Either way, you are doing something useful.
The question. A good generator gives real pictures a high probability . But for a VAE, means "add up, over every code, the chance of that code times the chance it draws " — an impossible sum over the whole map. What can we compute and maximise instead?
The answer is the ELBO, the evidence lower bound. (The "evidence" is .) For any guess the encoder makes about which codes could have drawn :
The first two lines together are the ELBO. The ELBO is the platform, is the ceiling, and the gap is how wrong the encoder's guess is about the true codes behind . Its two parts are exactly the VAE loss of §4, with the sign flipped: rebuild well, and pay KL to the prior.
A whole example, by hand. Take the smallest possible model: just two codes, A and B, each chosen with chance . Code A draws our picture with chance , code B with chance .
That last line is the true posterior: given the picture, A is three times as likely as B. Now let the encoder guess , and compute the ELBO's parts: rebuild , KL .
| the encoder's guess | rebuild | KL to prior | ELBO | gap |
|---|---|---|---|---|
| (0.5, 0.5) — no idea | −1.0601 | 0 | −1.0601 | 0.1438 |
| (0.9, 0.1) — too sure | −0.6207 | 0.3681 | −0.9888 | 0.0725 |
| (0.75, 0.25) — the truth | −0.7855 | 0.1308 | −0.9163 | 0 |
Every row adds up: ELBO + gap , always. The "too sure" guess rebuilds best of all, but pays so much KL that its ELBO is lower than the truth's. The ELBO is highest exactly when the guess is the true posterior — and there it touches the ceiling.
Because the gap is a KL, and a KL is never negative (Unit 14). So the ELBO is always a floor under . Training pushes the floor up in two ways at once. Improving the decoder raises the ceiling itself — real pictures become more likely. Improving the encoder closes the gap — its guess gets closer to the true codes. We never compute the ceiling, and we never need to.
Two ways to read the same score.
| ELBO = rebuild − KL to prior | ELBO = − gap | |
|---|---|---|
| what you can compute | both parts, for any picture | neither part (both need the whole map) |
| what it tells you | the VAE loss, turned upside down | why the loss is a sensible thing to optimise |
| best guess | balance rebuilding against the pull | the true posterior (gap 0) |
Rule of thumb. Train with the left-hand form; understand with the right-hand one. The left form tells you what to compute; the right form tells you why it works — every step that raises it either makes the model better or makes the encoder's guess more honest.
Maximising the ELBO is not only "rebuild better". It does two jobs at once: it improves the decoder (a higher ceiling) and makes the encoder's guess closer to the truth (a smaller gap). In the table, the guess that rebuilds best, (0.9, 0.1), is not the one with the best ELBO.
We cannot compute how likely the model makes a picture, but we can compute a floor under it: rebuild well, stay near the prior. Raising the floor either raises the ceiling or closes the gap — and at the true posterior the floor touches the ceiling.
In the two-code toy, the encoder guesses : "certainly A". What happens to the ELBO compared with the truth ?
You make the decoder better: goes from 0.6 to 0.8 (with as before). Where does the best guess move, and what is the new ceiling?
For some guess , the rebuild part is −1.2 and the KL to the prior is 0.3, and you know . How big is the gap?
If you want the algebra · 2 proofs, step by step
Claim. For any guess : .
Claim. If the decoder says "the picture is plus bell-shaped pixel noise of spread ", then — so maximising the ELBO is minimising the VAE loss of §4.
In one sentence: The ELBO — rebuild well, stay near the prior — is a platform that always sits under the ceiling ; pushing it up either raises the ceiling or closes the gap, and at the true posterior the two touch.
Walking the latent map
Picture a huge map of a country where every village is a face. Villages next to each other hold faces that look alike. Walk north and the faces grow bigger; walk west and they start to smile. You can stop anywhere — even in a field between villages — and a face is waiting for you there too.
The question. Now that the map is full, how do we use it to make new faces — and what are its limits?
The VAE's map is called its latent space ("latent" means hidden: the code is never seen in the data). Three things become easy.
- Sampling. Draw — the same cloud the KL pulled everything towards — and decode. Each draw is a new face. This is the sculptor of §1: fixed hands (the decoder), a random lump ().
- Morphing. Take the codes of two faces and walk in a straight line between them, decoding as you go: one face turns smoothly into the other.
- Directions mean something. Because similar faces sit near each other, a direction on the map becomes a property: "this way is bigger", "that way is happier". In big VAEs such directions are found for hair, glasses or age.
The honest limit. VAE pictures are blurry. The rebuild loss is a squared error, and when the decoder is unsure between two possible pictures — a mouth slightly up or slightly down — the squared error is smallest for their average. An average of two sharp mouths is one soft mouth. So wherever the code does not pin a detail down, the VAE paints a blur. Keep this in mind: it is the gap that diffusion (Act III) closes.
Because of the overlapping clouds of §4. During training, every point near the centre was drawn from some face's cloud, and the decoder was asked to rebuild that face from it. Points between two clouds were trained on both faces, so the decoder learned to paint something between them. That is exactly what a smooth morph and a good random sample need: a decoder that was trained everywhere the prior puts its draws.
Two kinds of "in between", side by side.
| pixel average | decoded midpoint | |
|---|---|---|
| what it does | lays the two pictures on top of each other | walks halfway on the map, then draws |
| what you see | two faint outlines, two mouths — a double exposure | one face, middle-sized, with a middle smile |
| is it a face? | no | yes — the map only holds faces |
Rule of thumb. To blend two things, blend their codes, not their pixels. Straight lines in the latent space become curved, sensible paths among real-looking pictures.
A straight line on the map is not a straight line in pixel space. The pixel-space straight line from A to B passes through double exposures that are not faces at all. The decoder bends the straight latent line into a curve that stays among faces. "Halfway" on the map means "halfway in meaning", not "the average of the pixels".
A trained VAE is a map where every point is a picture: draw a point from the prior to create, walk a straight line to morph. Its weakness is blur — the squared-error rebuild paints the average wherever the code leaves a detail open.
You decode codes far outside the rings, at . What do you expect?
A VAE decoder is unsure whether a mouth pixel should be 0 (dark) or 1 (bright), each equally likely. Under squared error, what value does it paint?
If you want the algebra · 1 proof, step by step
Claim. If the true value of a pixel is random, the single guess with the smallest average squared error is the average .
In one sentence: A trained VAE is a map of faces you can walk — draw a point from the prior to create, walk a straight line to morph — but where the code leaves a detail open, its squared-error decoder paints the average, so its pictures are soft.
Forward: destroy a picture one small step at a time
Drop a single drop of blue ink into a glass of still water. At first it is a sharp little cloud with a clear shape. A second later it has spread a bit; a minute later it is a faint haze; after an hour the whole glass is an even pale blue, and nothing tells you what shape the drop once had.
Destroying is easy. Every moment the ink simply spreads a little more. Nobody has to plan it.
The question. The VAE drew a picture in one go, and it came out blurry. Diffusion takes the opposite road: it learns to undo destruction. But first we need the destruction itself. How do we turn a picture into pure static — in a way so simple that we know exactly what happened at every step?
A picture is a list of numbers (for our faces, 400 pixels, scaled to run from −1 to 1). We use the step of §2, over and over, with a small noise amount at step :
Shrink the picture a little, add a little noise — the chai glass. Every pixel gets its own noise.
By hand, three steps. Take at every step. The picture is shrunk by three times, and the three noises pile up. The two facts of §2 add them into one noise:
This is the key shortcut. We never have to walk the steps one by one: to jump straight to step , multiply the "keep" factors together, , and draw one noise:
It is the reparameterisation trick of §5 again: a formula of the picture and outside noise.
The real schedule. DDPM (Ho, Jain and Abbeel, 2020) uses steps, with rising in a straight line from 0.0001 to 0.02. Then
The signal-to-noise ratio compares the variance kept from the picture with the variance of the noise. At step 100 the picture is still 8.71 times louder than the noise. By step 500 the noise is about 12 times louder. At step 1 000 only of the picture survives: it is pure static, , whatever you started from.
Because every step is §2's step, which keeps the total size fixed while swapping picture for noise. Independent noises simply add their variances, so a thousand small noises are exactly one big noise, and a thousand small shrinks are one big shrink . The destination does not depend on the picture at all: every picture ends in the same . That fixed, easy destination is what will let us start the reverse journey from pure static.
Two schedules, side by side.
| linear (DDPM, Ho et al., 2020) | cosine (Nichol and Dhariwal, 2021) | |
|---|---|---|
| recipe | rises in a straight line, 0.0001 → 0.02 | follows a cosine curve from 1 to 0 |
| at t = 500 | 0.07859 | about 0.49 |
| how the picture fades | fast early: much of the late journey is already static | evenly across all the steps |
| good for | the original DDPM results | small pictures, where the linear one destroys detail too soon |
Rule of thumb. The schedule only decides how fast the picture fades. Whatever it is, the one-jump formula holds with its own — so you can always jump straight to any step.
No learning happens in the forward process. It is a fixed recipe with no weights: shrink, add noise, repeat. Everything a diffusion model learns is in the reverse direction, in the next sections. The forward process is only there to make training examples: a clean picture, a step , and the noise that was added.
A thousand small "shrink and add noise" steps are one big one. The picture survives with weight , the noise has weight , and at the end every picture is the same pure static.
Two steps with each. Write as one jump from .
With the linear schedule, you forward-noise two very different pictures — a face and a cat — to . How different are the two results?
At step 100 of DDPM, . Roughly how much louder is the picture than the noise, in variance?
If you want the algebra · 1 proof, step by step
Claim. If with fresh independent noise at every step, then for one standard noise , where .
In one sentence: The forward process spreads the ink — shrink a little, add a little noise, a thousand times — and because the noises add up into one, any step can be reached in a single jump, , ending in the same static for every picture.
The denoiser: guess the noise
An old photograph of your grandparents' wedding has faded and gathered dust. A restorer at a studio in Chandni Chowk looks at it for a long time and says: "This much of what you see is dust." He paints the dust out, and the wedding comes back.
He does not paint the picture from memory. He only has to be good at one thing: spotting the dust.
The question. The forward process is fixed. So what does a diffusion model actually learn?
It learns to be the restorer. A network looks at a noisy picture and the step number, and guesses the noise that was added. Training is a plain regression with squared error — the loss of Unit 10 and Unit 15:
- Take a real picture and a random step .
- Draw noise and make in one jump (§8).
- Ask the network for its guess , and pay .
That is all. No second network, no guessing game: the right answer — the noise — is known for every training example, because we added it ourselves. (Underneath, it is §6 again: Ho and colleagues showed that this plain squared error is an ELBO, like the VAE's, in which the noisy pictures play the part of the code — with the steps weighted a little differently. The bookkeeping just comes out very simple.)
Knowing the noise is knowing the picture. Solve the one-jump formula for :
Paint out the dust, then turn the brightness back up. By hand, with one number: , (so , ), and noise :
A perfect guess gives the picture back exactly. A guess that is 0.2 too small leaves some noise in, and the rescaling blows it up a little.
What network? For pictures, a U-Net (a network that squeezes the picture down and widens it back up, with shortcuts between matching sizes), or a transformer (Unit 18) that reads the picture as patches. Either way it also reads , so it knows how much dust to expect.
Because squared error teaches averages (the drawer of §7). Many different clean pictures could have produced the same noisy , and the network cannot know which one it was. So it learns the average noise over all of them — and, through the formula, the average clean picture. When the noise is small, only one clean picture fits, and the average is sharp. When the noise is huge, everything fits, and the best guess is the average of the whole dataset. Each guess is honest about how much it can know.
What should the network predict? Two choices, side by side.
| the network predicts | the clean picture | the noise (DDPM) |
|---|---|---|
| loss | ||
| size of the target | a whole picture, every step | always : the same size at every step |
| convert to the other | ||
| in practice | works; often weaker at low noise | the standard choice since DDPM |
Rule of thumb. Predict the noise: the target always has the same size, which keeps training steady at every step. §10 adds a third choice, the score. Any of the three can be turned into the others with one line of algebra.
The network is not used to draw the final picture in one go. From a very noisy input its best guess is a blurry average — in the widget, a blob near the centre. That is why diffusion does not stop at the first guess. It uses the guess to take one small step back, looks again, guesses again, and sharpens the picture over many steps (§11).
A diffusion model is a restorer trained by squared error to spot the dust: noise a real picture by a known amount, and ask for the noise back. Knowing the noise is the same as knowing the clean picture — as well as it can be known from what is left.
, (so , ), and the restorer guesses . What is ?
A perfect restorer sees pure static at . What is its best guess of the clean picture?
If you want the algebra · 1 proof, step by step
Claim. Among all functions of , the one with the smallest average is ; and then equals , the average clean picture behind .
In one sentence: A diffusion model is a restorer who, shown a noisy picture and how noisy it is, guesses the dust by plain squared-error regression — and from the dust guess, is the best clean picture that can be known.
The score: a compass pointing at the data
You are lost in fog in the hills above a few villages. You hold a strange compass: it always points towards the most likely place to find people. Far out in the fog it points vaguely towards the middle of all the villages. As you come closer, it starts to choose: this village, not that one. Right at the edge of a village it points sharply to its centre.
The question. The restorer's noise guess feels like a trick for one picture. Is there a single field — an arrow at every point of space — that tells us which way real data lies?
There is. It is called the score: the slope (gradient, Unit 6) of the log of the density, . At every point it is an arrow pointing uphill — towards where data is more likely.
One village, by hand. For a bell curve , , so its slope is
With and : at the score is (go right, towards 2); at it is (go left). The farther away, the stronger the pull; at the centre, 0.
The noise guess is the score in disguise. Given one clean , the noisy is a bell curve with centre and variance . Its score is . So
Check it on §9's numbers (, , ): from the bell curve, ; from the noise, . The same arrow, both ways. A trained restorer is a compass.
Two villages. Now the data is two bumps: half the points near , half near , each with variance 0.01. Noise it to : the bumps move to , and each widens to variance . At , how much does each village "claim" the point? Compare the two bells (the responsibilities, as in Unit 14's Bayes):
The score is the claims times each village's own pull:
A strong arrow to the right: the compass has picked the nearer village.
In two dimensions. The rangoli is 55 small villages. The same rule holds: at every point, the score is the claims of the villages times their pulls — and we can compute it exactly. Below, the height of the landscape is of the noisy rangoli, and the gold arrows running over it are the compass. In this widget, and in all of Act III, the trained network is replaced by this exact answer, so every arrow is true. A real model learns an approximation of this field from examples.
Because of one small miracle, called Tweedie's formula: take one step along the score, of size , and you land exactly on the restorer's best average guess, scaled: . So the arrow points from where you are to the average of the clean pictures that could have made this noisy one. Far away, that average is the centre of everything. Close to one village, it is that village. The compass is just the restorer's guess, turned into a direction.
Three ways to say the same thing, side by side. Any one of them can be computed from the others.
| the noise guess | the clean guess | the score | |
|---|---|---|---|
| answers | "how much of this is dust?" | "what was under the dust?" | "which way is more likely?" |
| from | — | ||
| picture | the dust layer | the restored photo | a compass needle |
| who uses it | DDPM training (§9) | DDIM's jump (§12) | score models, Langevin (§11) |
Rule of thumb. Train the noise, think in scores. When you picture a diffusion model, picture a field of arrows that sharpens as the noise goes down.
The score is not the probability. It points uphill, but it says nothing directly about how high you are. The compass reads 0 at the very top of a village — and also exactly halfway between two equal villages, where the pulls cancel. A zero score means "flat", not "likely".
The score is a compass at every point, pointing towards more likely data. For a mixture it is each village's pull, weighted by how strongly that village claims the point. A noise predictor is a compass: divide its guess by .
Two equal villages at (after noising), and you stand exactly at . What does the compass read?
You noise the two-village data much more, to . At , what happens to the compass compared with ?
A trained model sees at and predicts . What is its score there?
If you want the algebra · 2 proofs, step by step
Claim. For the noised data , the score is . (For one known this is just the score of the bell curve .)
Claim. For equal-weight bells (the noised rangoli: , ), the score is , with claims .
In one sentence: The score is a compass pointing towards more likely data — fuzzy and central in thick fog, sharp and local near a village — and a noise predictor is that compass in disguise: .
Walking back from static
Film the ink drop spreading in the glass, and play the film backwards. The even haze gathers, a little at a time, into a faint cloud, then a sharper one, until the single drop hangs there again, with its shape.
Played backwards, every small moment looks like "the ink moves a little towards where it is thicker". That is all the reverse film is.
The question. We have a compass that works at every noise level. How do we use it to turn pure static into a picture?
Start from pure static, , and repeat for :
- Ask the restorer for the noise, — the compass.
- Step a little uphill: remove a small part of the guessed noise and undo one step's shrink.
- Add a little fresh noise, of the right size for this step.
DDPM's step says exactly how much of each:
with and . Read it aloud. : only the share of the guessed noise that this one step added. : undo this step's shrink. : a fresh jiggle.
By hand. (so ), , , , and the fresh draw is :
You have met this walker before. Write as the score (§10) and the step has the same shape as Langevin dynamics — a small step along the score, plus a jiggle:
For the score is . From with and no jiggle (): . That is Unit 9's gradient descent walker, walking downhill on the landscape — with a jiggle at every step (Unit 9's noise as a friend), so that the walkers spread over the whole distribution instead of all piling onto its highest point.
Because each forward step is tiny. When a step adds only a little noise, undoing it is almost a bell curve too — its centre given by the compass, its spread . (This is Unit 8's Taylor idea: over a small enough step, everything looks simple.) So a thousand small, simple reverse steps undo a thousand small forward steps. And the fresh noise matters: the reverse film must end with the right spread of pictures, and a compass alone only knows the direction of more likely data.
With and without the jiggle, side by side. These are the widget's own counts, 3 000 points, 100 steps, the same starting static.
| DDPM, fresh noise on | fresh noise off (only the "mean" step) | Langevin (a fixed landscape) | |
|---|---|---|---|
| each step | compass step + | compass step only | score |
| where the points end | spread over the whole rangoli | all on the centre dot | spread over , if run long enough |
| parts of the rangoli used | 55 of 55 | 1 of 55 | — |
| noise level | walks down from 1 000 to 0 | walks down from 1 000 to 0 | one fixed level |
Rule of thumb. Keep the jiggle. The compass tells each walker where "more likely" is; the jiggle keeps the walkers from all agreeing. Want a sampler without randomness? Use DDIM (§12), which is built to be deterministic — not DDPM with the noise switched off.
Removing the added noise does not give "cleaner" samples. It gives less varied ones. Without the jiggle, the early steps pull every walker towards the middle of everything, and they all end in the same place — here, all 3 000 points on the single centre dot of the rangoli. The randomness is not a flaw in the sampler; it is what makes it a sampler.
Generation is the ink film played backwards: start from static, and at every step move a little along the compass and add a little fresh noise. It is gradient descent on with a jiggle, walked down through the noise levels from very blurry to sharp.
In the worked step, the fresh draw is instead of . What is ?
You run the reverse walk with no fresh noise. What do the finished samples look like?
One Langevin step for , from , with and jiggle . Where do you land?
If you want the algebra · 2 proofs, step by step
Claim. If we knew , the step back from would be a bell curve with centre . Putting in from gives exactly DDPM's mean .
Claim (for a bell). For , the Langevin step maps to , whose only fixed point for small is — the target itself.
In one sentence: To create, play the ink film backwards — start from static, and a thousand times move a little along the compass and add a little fresh noise — which is Unit 9's downhill walker on , with the jiggle that keeps every walker from ending in the same place.
Faster: DDIM and the smooth path
You are coming down a long staircase in the dark, one step at a time, holding the rail. Then someone switches on the light. Now you can see the landing far below, and you can take the stairs three or four at a time — you know where you are heading.
The question. DDPM needs a thousand steps, and every step runs the whole network once. Can we reach the picture in far fewer steps?
DDIM (Song, Meng and Ermon, 2021) takes big, deterministic jumps. At every visit it does two things with the same noise guess:
- Look at the landing: estimate the clean picture, (§9).
- Jump straight to a much lower noise level , re-noising the landing with that same :
By hand. , , : the landing is (as in §9). Jump to :
No fresh noise is drawn. So the walk is deterministic: the same starting static always gives the same picture. And because it never throws a random jiggle in, the path is smooth, and it can be walked with big strides. (In the limit of tiny steps it follows an ordinary differential equation, the probability-flow ODE: a smooth river that carries every point of the static to a picture.) Song and colleagues report that 50 DDIM steps give pictures close to those of the full 1 000-step DDPM.
Because the restorer's guess already contains a full picture, . DDPM uses only a sliver of it per step and relies on fresh noise to keep the right spread. DDIM instead keeps the noise it already has — the same — and re-mixes it with the landing in exactly the proportions the forward process would have at level . So after every jump the point looks like a proper sample of level , and the next compass reading is trustworthy even after a big stride.
DDPM and DDIM, side by side. The last row is the widget's own count: 400 walkers on our rangoli.
| DDPM (§11) | DDIM | |
|---|---|---|
| each step | small compass step + fresh noise | estimate , jump, re-noise with the same |
| randomness | at every step | only the starting static |
| same start twice | two different pictures | the same picture |
| typical steps | 1 000 | 25–100 |
| same network? | yes | yes — only the sampler changes |
| our rangoli, 400 walkers | 50 steps: about 88% on the shape; 100 steps: about 95% | 50 steps: 92.5%; 100 steps: about 95% |
Rule of thumb. Train once, sample however you like. DDIM with 50–100 steps is the usual fast choice; add back some randomness when you want more variety between runs.
Fewer steps are not free. Each jump trusts one compass reading over a long distance; if the stride is too long, the reading is out of date by the time you land. With 10 steps, fewer than half of our walkers land on the rangoli, with DDIM as well as with DDPM.
DDIM looks at the landing and jumps: estimate the clean picture, then re-noise it with the same noise guess to a much lower level. No fresh randomness, so the path is smooth, the same start gives the same picture, and a few dozen strides can do the work of a thousand small steps.
A DDIM jump from , , , all the way to (no noise at all). Where does it land?
You run DDIM twice from the same starting static, with the same trained network. What do you get?
If you want the algebra · 1 proof, step by step
Claim. If the network is exact for a single clean picture (so and ), then the DDIM jump gives exactly — a proper level- sample of the forward process, with the same noise.
In one sentence: DDIM switches on the light on the staircase — at each visit it estimates the clean picture and jumps far down with the same noise guess — so the path is smooth, the same start always gives the same picture, and a few dozen strides replace a thousand steps.
Steering with words: guidance and latent diffusion
You are driving to a friend's house with the map app on. At a busy junction the voice says: "Keep left." Your own habit — "most people go straight here" — pulls you one way; the voice pulls you another. A good voice even says: "More to the left than you think." It takes the difference between where you would go and where you should go, and makes it bigger.
The question. A diffusion model draws something that looks real. How do we make it draw what we ask for — "a cat on a scooter" — and how do big models afford to do it on huge pictures?
Step 1: give the restorer the request. Train the noise guesser with the text as an extra input: , where is the prompt. A transformer (Unit 18) reads the text into vectors, and the picture network looks at them with cross-attention: every patch of the picture asks the words "which of you is about me?". Sometimes, during training, the prompt is dropped on purpose, so the same network also learns the unconditional guess .
Step 2: go past the request. Classifier-free guidance (Ho and Salimans, 2022) mixes the two guesses with a weight :
By hand: , , gives . The difference 0.3 is "what the request adds"; guidance adds it three times. ignores the prompt, follows it plainly, and says "more to the left than you think".
On our rangoli we can do it exactly: the "prompt" is a class — the petals or the lamps — and the conditional guess is the exact noise guess of that class's parts alone. So guidance, too, is computed with no network at all.
Turn the guesses into scores (§10). The difference is, up to a factor, the slope of — "how much more does this picture look like the request?", by Bayes (Unit 14). Guidance with weight samples as if that vote were raised to the power . A louder vote pushes the walkers to the places that are most typical of the class and least like anything else — sharper and more faithful, but less varied.
Step 3: diffuse in a small space. A 512 × 512 colour picture is numbers, and a diffusion model must run a big network on all of them at every step. Latent diffusion (Rombach and colleagues, 2022 — the idea behind Stable Diffusion) first trains a VAE-like autoencoder (§3–§4) that squeezes the picture into a latent of numbers — 48 times fewer — and runs the whole diffusion there. At the end the decoder turns the finished latent into the full picture. Act II and Act III join: the VAE's map becomes the place where diffusion walks.
The steering choices, side by side.
| 0 | 1 | 3 to 7 (common for pictures) | |
|---|---|---|---|
| what it samples | anything, ignoring the prompt | the prompt's distribution, plainly | the most typical pictures of the prompt |
| faithful to the prompt | no | yes | very |
| variety | most | the prompt's own | less; too high looks over-cooked |
Rule of thumb. Guidance is a dial between "varied" and "on-message". Latent diffusion is how the dial stays affordable: squeeze with a VAE, diffuse the code, decode once at the end.
is plain conditional sampling — no guidance at all. "Guidance" means : the model is pushed beyond its own conditional answer, away from the generic one. The widget shows it: at every lamp gets its share; only from does the voice start to insist.
Steer by taking the difference the request makes to the noise guess and making it louder; walk in a VAE's small latent space to keep it cheap. Words guide the picture through the same compass that made it.
, , and . What is the guided guess?
In the widget you raise from 1 to 5 for the class lamps. What happens?
If you want the algebra · 1 proof, step by step
Claim. In scores, is the noise guess of the tilted density : it samples as if the "does this look like ?" vote were raised to the power .
In one sentence: Guidance is a sat-nav voice saying "more to the left than you think" — — and latent diffusion runs the whole walk in a VAE's code, 48 times smaller, before decoding once at the end.
What to carry forward — and the whole course inside one picture
Thirteen pictures hold this unit. If you can draw each one and say its line, you own the unit.
1 · The lump of clay
To create is to sample: , a fixed skill applied to fresh noise.
2 · The chai glass
Shrink by , add noise of variance : the glass stays full, and every start ends in .
3 · Two numbers on the phone
An autoencoder squeezes and rebuilds; with straight lines it is PCA. Its map has empty land.
4 · A neighbourhood, not a house
A VAE's cloud plus a KL price fills the map.
5 · The wobble on a card
: roll the dice first, and blame flows through.
6 · A platform under the ceiling
: rebuild well, stay near the prior.
7 · A map of faces
Sample from the prior, walk straight lines to morph; squared error paints blur.
8 · The ink drop
: a thousand noisings in one jump.
9 · The restorer
Learn the dust by squared error; .
10 · The compass
: fuzzy far away, sharp near a village.
11 · The film backwards
Step along the compass, add a jiggle, a thousand times. No jiggle, no variety.
12 · The light on the stairs
DDIM: estimate the landing, jump with the same noise guess. Same start, same picture.
13 · The sat-nav voice
Steer with : take the difference the request makes and say it louder — "more to the left than you think". And to keep it cheap, run the whole walk in a VAE's small code and decode once at the end.
The families of generators, again — now you know what is inside.
| autoregressive (Unit 19) | VAE | GAN | diffusion | |
|---|---|---|---|---|
| trained by | next-token cross-entropy | the ELBO | a forger–detective game | squared error on the noise |
| draws with | one token at a time | one decoder pass | one generator pass | 25 to 1 000 small steps |
| best at | text, code | smooth maps, compression | fast sharp pictures | the sharpest, most varied pictures; steering |
| its weak spot | slow for long outputs | blur | unstable, forgets kinds of data | many steps |
The whole course, inside two machines. An LLM (Unit 19) and a diffusion model look nothing alike: one writes a word at a time, the other paints a whole picture out of static. Yet follow either one from start to end, and every stage is a tool you built in this course.
The same story, as a table you can read row by row:
| what you learned | where it lives now |
|---|---|
| Vectors and dot products (Unit 3) | attention scores in the LLM; cross-attention from the picture to the prompt |
| Matrices and rank (Units 1, 5) | every layer; low-rank fine-tuning of both machines |
| Eigenvectors, SVD, PCA (Units 4, 5, 12) | the autoencoder's squeeze; the latent space of latent diffusion |
| Derivatives, the chain rule, backprop (Units 6, 7, 15) | training both; the reparameterisation trick; the score is a gradient |
| Taylor (Unit 8) | why tiny reverse steps are almost bell curves |
| Gradient descent, noise, Adam (Units 9, 11) | training both; and sampling itself — Langevin is descent with a jiggle |
| Probability, Gaussians, softmax, KL (Unit 14) | every loss: cross-entropy for the LLM, the ELBO's KL for the VAE, squared error (a Gaussian likelihood) for diffusion; sampling from both |
| Attention and transformers (Unit 18) | the LLM's whole body; the text reader and often the denoiser of a diffusion model |
Rule of thumb. When you meet a new model, ask three questions: what noise goes in, what is it trained to predict, and how does it walk from noise to data? Every generator in this unit is an answer to those three.
A friend says: "Diffusion models have nothing to do with gradient descent — they are trained differently and they sample differently." Which is the best reply?
In one sentence: A machine creates by learning to walk from noise to data — through a small map (the VAE) or down a thousand steps of fading static along a learned compass (diffusion) — and every step of that walk is built from the vectors, derivatives, descents and probabilities of this course.
Practice arena — sixteen problems, solved in full
Sixteen problems, in the order of the unit: making samples from noise, the Gaussian toolkit, the KL of a cloud, the trick and its slopes, a whole ELBO by hand, the forward jump and a schedule's half-life, the restorer, the compass for one and two villages, one step of DDPM, Langevin and DDIM, guidance, and the latent squeeze. The tags say which are easy and which are hard. Every number here was checked by machine.
Three habits do most of the work. Square roots first: write down and before anything else — almost every formula uses them. Variances add, spreads do not. And check the sign of every score: it must point towards the data.
A tea stall's daily sales follow cups. (a) Turn the standard draws into sales. (b) Which would give a day of 245 cups?
What this tests. The stretch-and-shift generator of §1. Plan. forwards, then solve it for .
Show the full solution
answers at a glance: (a) 170, 206, 222.5 cups. (b) .
The generator never changes; only the noise does. Running it backwards, , is what an encoder does.
Waiting times follow an exponential curve with : . (a) Find the sampler . (b) Sample it at and . (c) Which gives the median wait, and what is it?
What this tests. The inverse-CDF trick of §1. Plan. Solve for .
Show the full solution
answers at a glance: (a) . (b) 0.6931 and 0.1116. (c) , .
Even noise in, any shape out: run the CDF backwards. The quantiles of the output are the quantiles of .
One noising step is . (a) For the fixed start , give the bell curve after one step (mean and spread). (b) If instead , what is the variance after one step? (c) For independent , with variances 1 and 2, find .
What this tests. The two facts of §2. Plan. Factors come out squared; independent variances add (a minus sign squares away).
Show the full solution
answers at a glance: (a) . (b) 3.4. (c) 17.
Only a start of variance exactly 1 stays at 1. Anything else drifts towards 1, step by step.
(a) Find . (b) A cloud centred at pays a KL of 0.3181 and is narrower than the standard one. Find its spread .
What this tests. The KL formula of §4, forwards and backwards. Plan. ; for (b), try simple spreads below 1.
Show the full solution
answers at a glance: (a) . (b) .
The spread part is 0 only at and grows on both sides.
An encoder gives , , and the wobble is . The loss is . Find (a) ; (b) and .
What this tests. The reparameterisation trick and the chain rule (§5). Plan. ; then times 1 and times .
Show the full solution
answers at a glance: (a) . (b) 0.2 and 0.06.
The slope to is the slope to times the wobble: a draw that landed on the other side () would push the other way.
Two codes A and B, each with prior 0.5. , . (a) Find , and the true posterior. (b) For , find the rebuild, the KL to the prior, the ELBO and the gap. (c) The same for . (d) Check that the gap in (c) equals .
What this tests. §6 end to end. Plan. rebuild , KL , ELBO = rebuild − KL, gap ELBO.
Show the full solution
answers at a glance: (a) 0.5, −0.6931, (0.9, 0.1). (b) −1.2040, 0, −1.2040, gap 0.5108. (c) −0.7645, 0.0823, −0.8468, gap 0.1537. (d) equal.
The closer the guess is to the posterior, the smaller the gap — here (0.9, 0.1) would close it completely, with ELBO .
A short schedule has . (a) Find . (b) Write as one jump from . (c) Evaluate it for , .
What this tests. The closed form of §8. Plan. Multiply the keep factors ; take square roots.
Show the full solution
answers at a glance: (a) 0.36. (b) . (c) 0.2.
The two weights always satisfy : the glass stays full.
A schedule uses the same at every step. (a) Find a formula for the first step at which drops below a level . (b) Apply it with , . (c) And with .
What this tests. , turned around with logs. Plan. Solve ; both logs are negative, so the inequality flips.
Show the full solution
answers at a glance: (a) the first whole . (b) 69. (c) 230.
A constant is a steady decay: every 69 steps it halves what is left. DDPM's is not constant — it starts tiny and grows — so its halfway point (step 260) has to be counted by multiplying the factors one by one.
At the restorer sees and guesses . (a) Find . (b) If the true clean value was 1.4, what noise was really added, and what is the training loss?
What this tests. from , and the other way round (§9). Plan. , .
Show the full solution
answers at a glance: (a) 1.375. (b) , loss .
A small error in becomes an error in multiplied by : here 0.75 times as big.
(a) For (variance 0.5), find the score at and at . (b) A single clean point is noised to , and you see . Find the score there, and the noise guess it corresponds to.
What this tests. The score of a bell, and score (§10). Plan. ; the noisy point is .
Show the full solution
answers at a glance: (a) −2 and +2. (b) score 0.4, .
Score and noise guess always have opposite signs: the noise pushed the point away; the compass points back.
Data: half the points at , half at , each with variance 0.04. It is noised to . (a) Where are the two noisy villages, and what is their variance? (b) At , find the two claims. (c) Find the score at . Which way does it point, and why?
What this tests. The mixture compass of §10. Plan. Centres , variance ; claims from the two bells; score = claims × pulls.
Show the full solution
answers at a glance: (a) , 0.6544. (b) . (c) , gently to the left.
The nearer village does not always win the compass: a strong pull from a far village, weighted by its claim, can outweigh a weak pull from a near one.
A DDPM step with , , , and fresh draw . Find (a) the mean of the step, (b) , (c) .
What this tests. DDPM's step (§11). Plan. , , .
Show the full solution
answers at a glance: (a) . (b) . (c) .
Remove only this step's share of the noise, undo this step's shrink, then jiggle. Never remove all of in one DDPM step.
Target . One Langevin step from with and jiggle . Where do you land?
What this tests. (§11). Plan. The score is .
Show the full solution
answer at a glance: .
The downhill part pulls towards the peak at 1; the jiggle, of size , keeps the walkers spread with the right width.
At a walker is at , and the restorer guesses . (a) Find . (b) Jump with DDIM to . (c) Where would a jump to land?
What this tests. The two moves of DDIM (§12). Plan. , , , .
Show the full solution
answers at a glance: (a) 1. (b) . (c) 1.
DDIM re-uses the same : no new randomness, so the same start always gives the same picture.
For one pixel pair, the unconditional guess is and the conditional guess is . (a) Find the guided guess for . (b) Which makes its first entry 1.3?
What this tests. Classifier-free guidance (§13), forwards and backwards. Plan. , entry by entry.
Show the full solution
answers at a glance: (a) . (b) .
gives exactly ; every extra unit of adds one more copy of the difference the prompt makes.
A 1024 × 1024 colour picture is squeezed by an autoencoder into a 128 × 128 × 4 latent. (a) How many numbers before and after, and by what factor? (b) Show that squeezing each side by a factor into channels shrinks a colour picture by , and apply it to , .
What this tests. Latent diffusion's saving (§13), as a general formula. Plan. Count numbers; each side shrinks by , channels go from 3 to .
Show the full solution
answers at a glance: (a) 3 145 728 → 65 536, 48 times. (b) ; 48.
The diffusion network runs on the small latent at every one of its steps; the big decoder runs only once, at the end.