1. Home
  2. Explore
  3. Computer Science
  4. Probabilistic Brain & Generative Models

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Probabilistic Brain & Generative Models

Probability, Entropy, and Divergence: Foundational Concepts for Generative Modeling

Probability Distributions

A probability distribution is a function that maps each possible state of a system to a number between 0 and 1, reflecting the degree of belief that the state will occur. The probabilities of all possible states must sum to 1.

Two main interpretations of probability exist:

  • Frequentist: Probability is the long-run proportion of outcomes from repeated trials (e.g., rolling a die many times gives probability 1/61/61/6 for each face).

  • Bayesian: Probability is a degree of belief. This handles events that cannot be repeated, like "probability of rain tomorrow is 0.7" — it expresses 70% certainty, not a frequency.

All probability assignments must obey the law of total probability: for a set of mutually exclusive and exhaustive states, ∑iP(statei)=1\sum_i P(\text{state}_i) = 1∑i​P(statei​)=1.

Distributions can be:

  • Discrete: e.g., uniform distribution for a fair die, each outcome has probability 1/61/61/6.

  • Continuous: e.g., Gaussian (bell-curve) distribution for adult heights. The distribution integrates to 1 (the area under the curve equals 1). This is conceptually the same as summation if you view the continuous variable as many tiny discrete bins.

Distributions can also be multivariate. For example, states that include both height and weight occupy a 2D plane — each point corresponds to a particular combination and has a probability value. In machine learning, we often work with very high-dimensional spaces; for instance, all possible 100×100100 \times 100100×100 pixel images live in a 10,000-dimensional space (one axis per pixel value). We assign a probability to every point in that space.

Sampling

Sampling is the process of generating an outcome from a probability distribution. Rolling a die gives a sample from its distribution. In generative AI, if we can draw samples from a high-dimensional distribution that captures the structure of natural images, we can generate new realistic images — unlike random independent pixel values, which always produce noise.

Sampling from a learned distribution is the core mechanism behind generative models.

Surprise

Surprise (or surprisal) quantifies how unexpected an event is. It should:

  • Be a positive number.

  • Be larger for less probable events.

  • Approach zero as probability approaches 1 (certain events are not surprising).

  • Be additive for independent events: if you predict the outcomes of three dice rolls correctly, you are about three times as surprised as for one die. Since independent probabilities multiply, surprise should add — this is achieved by using the logarithm:

Surprise(x)=log⁡1P(x)=−log⁡P(x)\text{Surprise}(x) = \log \frac{1}{P(x)} = -\log P(x)Surprise(x)=logP(x)1​=−logP(x)

This function assigns high surprise to rare events and low surprise to common ones.

Entropy

Entropy is the average surprise of a probability distribution. It measures the inherent uncertainty or randomness of that distribution. For a discrete distribution PPP, entropy is:

H(P)=∑xP(x)log⁡1P(x)H(P) = \sum_x P(x) \log \frac{1}{P(x)}H(P)=∑x​P(x)logP(x)1​

Or equivalently H(P)=−∑xP(x)log⁡P(x)H(P) = -\sum_x P(x) \log P(x)H(P)=−∑x​P(x)logP(x).

Example: A "thick coin" lands heads 49%, tails 49%, and on its side 2%. Surprise for heads/tails: log⁡(1/0.49)≈0.7\log(1/0.49) \approx 0.7log(1/0.49)≈0.7; surprise for side: log⁡(1/0.02)≈4\log(1/0.02) \approx 4log(1/0.02)≈4. The average surprise (entropy) is:

H=0.49⋅0.7+0.49⋅0.7+0.02⋅4≈0.8H = 0.49 \cdot 0.7 + 0.49 \cdot 0.7 + 0.02 \cdot 4 \approx 0.8H=0.49⋅0.7+0.49⋅0.7+0.02⋅4≈0.8

A fair coin (50/50) has lower entropy (H=1H = 1H=1 nit if using natural log). The thick coin has more inherent uncertainty because rare "side" outcomes increase average surprise.

Entropy depends only on the true probability distribution. In real-world scenarios, this true distribution is usually unknown and complex; we instead have an internal model — our belief about the distribution.

Cross-Entropy

Cross-entropy measures the average surprise you expect when observing outcomes from a true distribution PPP but using your model QQQ to assign probabilities. It is defined as:

H(P,Q)=∑xP(x)log⁡1Q(x)=−∑xP(x)log⁡Q(x)H(P, Q) = \sum_x P(x) \log \frac{1}{Q(x)} = -\sum_x P(x) \log Q(x)H(P,Q)=∑x​P(x)logQ(x)1​=−∑x​P(x)logQ(x)

Cross-entropy combines two sources of surprise:

  1. The inherent uncertainty of PPP itself.

  2. The discrepancy between QQQ and PPP.

Key property: H(P,Q)≥H(P)H(P, Q) \ge H(P)H(P,Q)≥H(P), with equality only when Q=PQ = PQ=P. Using an imperfect model can only increase average surprise — never decrease it.

Asymmetry: Swapping PPP and QQQ gives very different results.

  • Example 1 (believe fair, actually rigged): True PPP is rigged coin (heads 99%, tails 1%); model QQQ is fair (50/50). Cross-entropy:

H(P,Q)=0.99⋅(−log⁡0.5)+0.01⋅(−log⁡0.5)=1⋅0.693=0.693H(P, Q) = 0.99 \cdot (-\log 0.5) + 0.01 \cdot (-\log 0.5) = 1 \cdot 0.693 = 0.693H(P,Q)=0.99⋅(−log0.5)+0.01⋅(−log0.5)=1⋅0.693=0.693
  • Example 2 (believe rigged, actually fair): True PPP is fair; model QQQ is rigged (heads 99%, tails 1%). Cross-entropy:

H(P,Q)=0.5⋅(−log⁡0.99)+0.5⋅(−log⁡0.01)=0.5⋅0.01005+0.5⋅4.605=2.307H(P, Q) = 0.5 \cdot (-\log 0.99) + 0.5 \cdot (-\log 0.01) = 0.5 \cdot 0.01005 + 0.5 \cdot 4.605 = 2.307H(P,Q)=0.5⋅(−log0.99)+0.5⋅(−log0.01)=0.5⋅0.01005+0.5⋅4.605=2.307

The second value is much larger because whenever tails occurs (half the time), surprise is extreme under the wrong model.

Kullback-Leibler (KL) Divergence

KL divergence measures the extra surprise caused by using model QQQ instead of the true distribution PPP — it isolates the penalty for model inaccuracy. It is defined as:

DKL(P∥Q)=∑xP(x)log⁡P(x)Q(x)=H(P,Q)−H(P)D_{KL}(P \parallel Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)} = H(P, Q) - H(P)DKL​(P∥Q)=∑x​P(x)logQ(x)P(x)​=H(P,Q)−H(P)

KL divergence = cross-entropy (total surprise) minus entropy (inherent surprise). It quantifies the inefficiency of using QQQ to approximate PPP.

Properties:

  • DKL(P∥Q)≥0D_{KL}(P \parallel Q) \ge 0DKL​(P∥Q)≥0 (Gibbs' inequality), with equality only when P=QP = QP=Q.

  • Not symmetric: DKL(P∥Q)≠DKL(Q∥P)D_{KL}(P \parallel Q) \neq D_{KL}(Q \parallel P)DKL​(P∥Q)=DKL​(Q∥P).

KL divergence is the natural objective for learning a model QQQ that approximates the true data distribution PPP.

Application to Machine Learning

In generative modeling, the goal is to learn a probability distribution that approximates the true distribution of data (e.g., all possible cat images). We parameterize a model QθQ_\thetaQθ​ (e.g., a neural network) and optimize its parameters θ\thetaθ to make QθQ_\thetaQθ​ as close to PPP as possible.

Why minimize cross-entropy instead of KL divergence? The KL divergence objective is:

min⁡θDKL(P∥Qθ)=min⁡θ[H(P,Qθ)−H(P)]\min_\theta D_{KL}(P \parallel Q_\theta) = \min_\theta [ H(P, Q_\theta) - H(P) ]minθ​DKL​(P∥Qθ​)=minθ​[H(P,Qθ​)−H(P)]

But H(P)H(P)H(P) is a constant determined only by the true data distribution — it does not depend on θ\thetaθ. Therefore, minimizing DKLD_{KL}DKL​ is equivalent to minimizing H(P,Qθ)H(P, Q_\theta)H(P,Qθ​) (cross-entropy). The entropy term just shifts the loss by a fixed amount. In practice, we minimize cross-entropy because it is simpler and computationally cheaper (no need to estimate the entropy of the training data).

Minimizing cross-entropy is the practical way to minimize KL divergence between model and data.

This principle underlies many machine learning algorithms, especially in generative models (e.g., variational autoencoders, diffusion models). Additional techniques like variational bounds extend this idea to cases where direct maximum likelihood is intractable, but the core remains: learning a distribution means minimizing the cross-entropy (or equivalently KL divergence) between the model and the true data distribution.

Summary: The concepts of probability distributions, surprise, entropy, cross-entropy, and KL divergence form the language of uncertainty. They allow us to quantify how well a model captures data, providing the mathematical foundation for training generative models that can create realistic new samples.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent