ID-5-02 (TO) · Mathematical Foundations of Diffusion Models · W03 demo

The KDE Lab

A kernel density estimate is a pile of little Gaussians, one per data point. Everything hinges on how wide you make them. Too narrow and you are drawing the sample; too wide and you are drawing nothing at all.

Act IOne bump per data point

The data below is drawn from a mixture of three normal distributions. Forget that for a moment and look only at the estimate: put a Gaussian of width h on top of every observation, divide by n so the total area is one, and add them up. That sum is the kernel density estimate

p̂h(x) = (1/nh) ∑i φ((x − xi)/h)

Individual kernels, and their sum

estimate p̂h individual kernels samples (rug)
With few points the bumps are visible as bumps. Widen h and they merge into a single smooth curve; narrow it and each observation becomes its own spike. Nothing else is going on — a KDE really is just this sum.

Act IIBandwidth is the whole game

Now the truth is drawn too, in grey, so you can see what is being estimated. The three components sit at different places with different widths and weights. Sweep h across its range and watch the estimate fail in two opposite ways.

Estimate against the truth

Small h: low bias, high variance — the estimate chases individual samples and invents modes that are not there. Large h: low variance, high bias — real modes are smeared together and the estimate is confidently smooth and wrong. The interesting question is where in between to stand.

Act IIIThere is a best h, and it moves

Because we know the truth here, we can score every bandwidth. Below is the integrated squared error ∫(p̂h − p)²dx as a function of h, computed on the current sample. The curve is U-shaped: variance falls and bias rises, and the minimum is the compromise.

Error against bandwidth

Push n up and two things happen: the whole curve drops, and its minimum slides left — more data buys you the right to be less smooth. The optimal bandwidth shrinks like n−1/5 and the error it achieves falls only like n−4/5, which is already slower than the parametric n−1.

And that is in one dimension. The exponent is n−4/(p+4) in p dimensions. At p = 10 matching this accuracy takes roughly 400,000 samples; at p = 100 it takes more samples than there are atoms within reach. The U-curve does not disappear in high dimension — it just flattens out at a level of error you cannot afford.