Skip to content
DineshKumar Sarangapani
All writing

Section 1: The dataset and the problem

The hidden distribution, the dataset I actually get, and why generative modeling starts there.

I am working through Mathematical Foundations of Generative AI, Prof. Prathosh AP’s public lectures. The playlist is the spine. These notes are my deep dive on each section: a visual when the picture is the point, a detour when a prerequisite is doing real work, and every formula read aloud with a plain-words line right after it.

Symbol cheat-sheet

SymbolSay it asIn plain words
DD”capital D”the dataset: the list of real examples I actually observe
{x1,x2,…,xn}\{x_1, x_2, \dots, x_n\}”the set x-one through x-n”a collection of nn data points
nn”n”how many examples are in the dataset
xix_i”x-i”the ii-th data point, e.g. one image as a list of numbers
dd”d”dimensionality: how many numbers it takes to describe one data point
∈\in”in”belongs to the set
R\mathbb{R}, Rd\mathbb{R}^d“the reals”, “R to the d”ordinary numbers; lists of dd ordinary numbers
∼\sim”drawn from”picked at random according to a distribution
∼iid\overset{\text{iid}}{\sim}”drawn i-i-d from”each point is drawn independently from the exact same distribution
⊥\perp”independent of”knowing one tells me nothing extra about the other
PxP_x, px(x)p_x(x)“P-x”, “p-x of x”the true, hidden data distribution and its density at xx
PθP_\theta“P-theta”the distribution of outputs produced by my model
∫…dx\int \ldots dx”integral over x”add up continuously over all possible values of xx
∑i=1n\sum_{i=1}^n“sum from i equals 1 to n”add up one term for each of the nn items
Ex∼Px[h(x)]\mathbb{E}_{x \sim P_x}[h(x)]”expected value of h of x, with x drawn from P-x”the long-run average of h(x)h(x) over random draws from PxP_x
→ n→∞ \xrightarrow{\,n\to\infty\,}“approaches as n goes to infinity”gets closer and closer as the sample size grows
∏t\prod_t”product over t”multiply these terms together, one per step tt
p(a∣b)p(a \mid b)“probability of a given b”how likely aa is once bb is already known

Section 1: The dataset and the problem

Everything later in the playlist — GANs, VAEs, diffusion, transformers, state-space models, and preference tuning — starts from the same setup. I want this part solid before I touch a model.

The setup I am carrying:

Data D={x1,x2,…,xn}∼iidPxD = \{x_1, x_2, \dots, x_n\} \overset{\text{iid}}{\sim} P_x (unknown), with xi∈Rdx_i \in \mathbb{R}^d, where dd is the dimensionality of the data. Example: xix_i is an image, 400×400×3400 \times 400 \times 3, so d=480,000d = 480{,}000. Goal: estimate PxP_x and learn to sample from it.

1. Intuition first

Somewhere there is a hidden recipe — a probability distribution — that produced every cat photo, every English sentence, every speech clip. I never get the recipe. I get a pile of examples it produced. Generative modeling is using that pile to reconstruct the recipe well enough to cook up new examples from the same kitchen.

2. Real-world analogy

Think of a production web service whose request process I cannot inspect. All I have is an access log of 1,000 requests. I want a load-testing tool that produces synthetic traffic indistinguishable from real users: same mix of endpoints, same payload sizes, same timing.

Load-testing analogyNotationIn plain words
The real, unknown user behaviourPxP_xthe hidden source of real data
One logged requestxix_ione observed sample
The fields in a log linethe dd coordinates of xi∈Rdx_i \in \mathbb{R}^dthe numbers that describe one sample
The access logdataset DDall nn samples I collected
The traffic generatorthe generative model PθP_\thetathe machine I am training
Synthetic requests it emitssamples from PθP_\thetanew points generated by my model

Two consequences follow. First, I do not need to write the user-behaviour formula down; I only need a generator whose output looks statistically indistinguishable from reality. That is why a GAN never writes PxP_x down at all. Second, replaying the log is not the goal. I want brand-new requests, not copies.

3. Visual

A hidden 2-D distribution plays the role of PxP_x. At first I only see the dots — the dataset. Reveal PxP_x to see what is normally invisible, and drag nn to see how more data reveals the shape.

Each “Draw a new dataset” gives a different DD and the same green PxP_x underneath. The dataset is random; the distribution is the fixed thing I am after. With n=5n = 5 the shape is a guess. With n=1000n = 1000 the two clumps are obvious.

4. The formula, decoded

D={x1,x2,…,xn}∼iidPx,xi∈RdD = \{x_1, x_2, \dots, x_n\} \overset{\text{iid}}{\sim} P_x, \qquad x_i \in \mathbb{R}^d

Read aloud: “The dataset DD equals the set of points x1x_1 through xnx_n, drawn independently and identically from PxP_x, where each xix_i belongs to Rd\mathbb{R}^d.”

In plain words: I have nn examples, each one is a list of dd numbers, and each one was picked independently from the same hidden source PxP_x.

Piece by piece:

SymbolWhat it isType / shapeIn plain words
DDthe dataseta set of nn vectorsthe only thing I actually observe
nnnumber of samplesintegermore data gives a clearer picture of PxP_x
xix_ione data pointvector in Rd\mathbb{R}^dan image, a sentence embedding, or a signal
dddimensionalityintegerhow many numbers describe one point
∼\sim”is drawn from”relationlinks data to its source
iidindependent and identically distributedassumptionmakes learning from samples legitimate
PxP_xtrue data distributiondistribution on Rd\mathbb{R}^dthe hidden target, unknown

Detour 1: Random variable and random vector

A random variable is a quantity whose value is decided by chance, like a die roll:

X∈{1,2,3,4,5,6}X \in \{1, 2, 3, 4, 5, 6\}

Read aloud: “capital XX belongs to the set one through six.”

In plain words: before I roll, the outcome is a random placeholder XX that will land on one of those six numbers.

A random vector is the same idea with several numbers at once, such as the height and weight of a randomly chosen person:

X∈R2X \in \mathbb{R}^2

Read aloud: “capital XX belongs to R-two.”

In plain words: one random draw gives me a pair of ordinary numbers at the same time. Capital XX means the random thing in general; lowercase xix_i means one specific value that actually came out.

Back to the main thread. Each image in my dataset is one specific outcome xix_i of a random vector with dd coordinates.

Detour 2: Distribution and density

PxP_x tells me how likely each possible value is. For a die it is a table: each face has probability 1/61/6. For continuous values, such as pixel intensities, it is a density px(x)p_x(x) — a heat map over space. High density means values land there often. In the chart above, the green shading is that density.

Two rules every density obeys:

px(x)≥0,∫Rdpx(x) dx=1p_x(x) \ge 0, \qquad \int_{\mathbb{R}^d} p_x(x)\, dx = 1

Read aloud: “p-x of xx is at least zero, and the integral over all of Rd\mathbb{R}^d of p-x of xx equals one.”

In plain words: likelihood is never negative anywhere, and if you add up the likelihood over every possible point in space, the total is 100% (which is 1).

Back to the main thread. I will write PxP_x for both the distribution and its density, and be explicit whenever the distinction matters.

Detour 3: iid (independent and identically distributed)

xi⊥xj(i≠j),xi∼Pxx_i \perp x_j \quad (i \ne j), \qquad x_i \sim P_x

Read aloud: ”xix_i is independent of xjx_j for ii not equal to jj, and every xix_i is drawn from PxP_x.”

In plain words: two rules hold at once:

  • Identically distributed (xi∼Pxx_i \sim P_x): every point comes from the exact same source — every log line came from the same production user population, not half from production and half from a test script.
  • Independent (xi⊥xjx_i \perp x_j): seeing x3x_3 tells me nothing extra about x7x_7 — the first roll of a die does not push the second roll around.

Back to the main thread. Why “unknown” is the whole problem: if I knew the formula for PxP_x, I would sample from it directly and stop. Every model in the playlist is a different trick for working with PxP_x through samples alone.

Why iid matters: the Law of Large Numbers. Because the samples are iid, I can replace an average over the unknown PxP_x with a plain average over my dataset:

1n∑i=1nh(xi)  → n→∞   Ex∼Px[h(x)]\frac{1}{n}\sum_{i=1}^n h(x_i) \;\xrightarrow{\,n\to\infty\,}\; \mathbb{E}_{x\sim P_x}[h(x)]

Read aloud: “one over nn times the sum from i=1i = 1 to nn of h(xi)h(x_i) approaches the expected value of h(x)h(x) under PxP_x as nn goes to infinity.”

In plain words: if you score every point in a large dataset and take the ordinary average, you get almost the exact same number you would get if you knew the true distribution PxP_x. That single fact is the engine behind every training loss in the course.

Why dd is so large. A 400×400400 \times 400 RGB image has three colour numbers per pixel:

d=400×400×3=480,000d = 400 \times 400 \times 3 = 480{,}000

Read aloud: “d equals 400 times 400 times 3, which is 480,000.”

In plain words: one single photo is a list of 480,000 numbers, or one point in R480,000\mathbb{R}^{480{,}000}. Real images occupy a tiny, thin region of that giant space; random lists of 480,000 numbers look like television static. This is the manifold hypothesis, and it comes back when naive GAN training fails.

Two jobs hiding in one goal

Given DD, “estimate PxP_x and learn to sample from it” splits into two distinct jobs:

JobIn plain wordsWho emphasises it
Density estimationGiven a point xx, output a number p(x)p(x) saying how real or likely it isAutoregressive models, VAEs (via a lower bound)
SamplingGenerate a brand-new point xx that looks like it came from PxP_xGANs (which never write a density down) and diffusion

A GAN can generate crisp images and still be unable to tell me the probability p(x)p(x) of a photo I hand it.

5. Tiny worked example

Let d=2d = 2 and n=3n = 3. Each point records (hours slept, coffees drunk) for a randomly surveyed person:

D={x1,x2,x3}={(7,1), (6,2), (8,0)}D = \{x_1, x_2, x_3\} = \{(7, 1),\ (6, 2),\ (8, 0)\}

Read aloud: “the dataset DD consists of three points: (7,1)(7, 1), (6,2)(6, 2), and (8,0)(8, 0).”

In plain words: I surveyed three people; the first slept 7 hours and drank 1 coffee, the second slept 6 hours and drank 2 coffees, and the third slept 8 hours and drank 0 coffees.

Suppose I want the true average coffee intake E[coffees]\mathbb{E}[\text{coffees}] under the unknown population PxP_x. By the Law of Large Numbers, I estimate it with the sample average:

E^[coffees]=1+2+03=1\widehat{\mathbb{E}}[\text{coffees}] = \frac{1 + 2 + 0}{3} = 1

Read aloud: “the estimated expected number of coffees is one plus two plus zero, divided by three, which equals one.”

In plain words: averaging the coffee column across my three people gives 1 coffee per day.

The generative goal is bigger than one average: I want a machine that outputs plausible new pairs like (7.5,0.5)(7.5, 0.5) — not copied from DD, and respecting the pattern that more sleep goes with less coffee.

6. Connect back

Every stretch of the lectures attacks “learn PxP_x from DD” with a different formula:

StretchModelCore formulaIn plain words
Weeks 1–3GAN / divergence minimisationx=gθ(z),  z∼N(0,I)x = g_\theta(z),\; z \sim \mathcal{N}(0, I)push random noise through a network and shrink a divergence to PxP_x
Weeks 4–5VAEPθ(x)=∫Pθ(x,z) dzP_\theta(x) = \int P_\theta(x, z)\,dzexplain each data point using a hidden latent code zz, and maximise a lower bound on log-likelihood
Week 6WGANWasserstein distancesame generator-critic game, but measure earth-mover distance so gradients do not flatten out
Weeks 7–8DDPM (diffusion)x0→x1→⋯→xTx_0 \to x_1 \to \dots \to x_Tslowly turn data into pure noise, then train a network to undo the noise step by step
Week 10Autoregressive / TransformerPθ(x)=∏tPθ(xt∣x<t)P_\theta(x) = \prod_t P_\theta(x_t \mid x_{<t})predict one token at a time given all earlier tokens
Week 11SSM / Mambastate-space recurrenceprocess sequences through a compact running state
Week 12RLHF / DPOpreference-tuned PθP_\thetanudge a trained generator toward outputs humans prefer

Quick check (optional)

  1. If a dataset mixes 5,000 phone photos and 5,000 medical scans, which part of iid breaks, and why does that hurt?
  2. What is dd for a 28×2828 \times 28 grayscale digit? For a 64×6464 \times 64 RGB image?
  3. Once I have DD, do I know PxP_x exactly? What changes as n→∞n \to \infty?

Next: Section 2: The general principle of generative models.