Deep Learning Notes-1: Polynomial Fitting, Probability Theory, and Information Theory Fundamentals
Deep Learning Notes-1, covering overfitting and underfitting, regularization, probability theory fundamentals (Bayes' theorem, Gaussian distribution, maximum likelihood estimation), and information theory (entropy and KL divergence). Corresponds to Chapters 1-2 of "Deep Learning: Foundations and Concepts".
Part 1/8 of the series → Next | Glossary
This series has 8 parts in total. It is recommended to read them in order, but if you are short on time:
Prerequisites: In theory, high school math is sufficient, and a foundation in calculus is preferable. If you know what a function is and what a derivative is, you can follow along. Goal of this part: After reading, you will understand—what overfitting is, how regularization works, and the most core concepts of probability theory and information theory.
Reference book: “Deep Learning: Foundations and Concepts” (2025) - by Christopher M. Bishop and Hugh Bishop
Chapter 1 Deep Learning Preliminaries: From Drawing a Line to Neural Networks
Fitting a Line Through a Bunch of Points
Imagine you have a scatter plot (say, the relationship between house area and price), and you want to draw a line to describe the pattern. How do you measure whether the line is drawn well?
The error function does exactly this: square the difference (error) between the actual value of each data point and the predicted value of your drawn line, sum them all up, and then divide by 2—this gives you a score of “how good the line is drawn”, where a smaller score means a better fit.
In plain words: error function = half the sum of the squares of each point’s “deviation”.
where is the prediction error of the -th point.
The polynomial function (the line you drew) is:
The error function is always ≥ 0 (because it is a sum of squares). Our goal is to find the set of parameters that minimizes this function, denoted as . How do we find it? Take the derivative of , set it to 0, and the resulting is .

Green is the error, red is the prediction function, blue is the true value
Model Complexity: Neither Too Simple Nor Too Complex Works
Choosing the order of the polynomial (model complexity) is a profound matter:
- Underfitting: The model is too simple and fails to learn even the basic pattern of the data (e.g., using a straight line to fit data that is parabolic in shape).
- Overfitting: The model is too complex and also learns the noise (random fluctuations) in the data as if it were a pattern, causing poor performance on new data (e.g., using a 10th-order polynomial to fit data that is inherently 2nd-order, causing the curve to oscillate violently).
How do we judge whether it is overfitting? Split the data into a training set (used to fit the model) and a test set (used to evaluate the model), and use the root mean square error to assess it:
This formula does two things: dividing by allows datasets of different sizes to be compared fairly, and taking the square root makes the error unit consistent with the original data (e.g., house prices in “yuan” rather than “yuan²”).

The higher the order, the more complex the model, and the more prone it is to overfitting; the lower the order, the more prone it is to underfitting
This is intuitive: the higher the order, the more “flexible” the curve, and the more easily it is led astray by random noise in the data, and the coefficients also become very large. At the same time, the larger the amount of data, the more it can support a complex model—this is like an exam with more questions, where it is harder to get things right by luck.
In short: model complexity must match the amount of data. With little data, use a simple model; only with a lot of data can you use a complex model.
Regularization: Putting a “Tightening Spell” on the Model
You might ask: since overfitting is caused by the parameters being too large, making the model too complex, can we just directly restrict the size of ?
Exactly! This is the idea of regularization. The approach is simple: add a penalty term after the original error function, penalizing whoever has a large :
This penalty term is also called weight decay, because it keeps “shrinking” the parameters . From a probability theory perspective (detailed in Chapter 2 later), this is equivalent to placing a Gaussian prior with mean 0 on the parameters —meaning we assume in advance that the parameters should be relatively small.
The key lies in the size of (lambda, the regularization coefficient):
- larger → heavier penalty → smaller → simpler model → more prone to underfitting
- smaller → lighter penalty → larger → more complex model → more prone to overfitting
How do you choose ? Try different values of on a validation set and see which one gives the smallest .

Root mean square error on the validation set vs λ
In short: regularization is like putting a tightening spell on the model—want the parameters to grow? First ask whether agrees.
Cross-Validation: How to Evaluate a Model Fairly?
Above we said to use a validation set to select , but the question is: how do we partition the validation set? If it is too large, there is not enough training data; if too small, the evaluation is inaccurate.
S-fold cross-validation is a clever solution:
- Randomly split the data into parts (e.g., K=4)
- Round 1: train on parts 2, 3, 4 and validate on part 1; Round 2: train on parts 1, 3, 4 and validate on part 2… and so on
- After running rounds, average all the validation errors

S-fold with K=4, red is the validation set
This way, every part of the data serves as the validation set once, making the evaluation result more reliable. The cost is that training is done times more.
Special case: when (the size of the dataset), only 1 sample is left out for validation each time, which is called leave-one-out.
S-fold cross-validation is often used to select the hyperparameters of neural networks (hyperparameter, i.e., parameters that need to be set manually before training, such as the number of hidden layer nodes and the learning rate), avoiding dependence on any particular partition.
Exercise 1
Background: Suppose you have a dataset containing 1000 examples, half positive and half negative. You want to use 70% for training and 30% for testing to evaluate the model. The question is: how many different partition ways are there?
500*70%=350, i.e., draw from the positive examples and from the negative examples, giving a total of draws.
Exercise 2
Background: A very “lazy” classifier—it only predicts whichever class is more frequent in the training set, and guesses randomly if they are equal. Use this extreme classifier to understand the difference between cross-validation and leave-one-out.
Suppose the learning algorithm’s model makes predictions according to the probability of class occurrence, predicting a new example as the class with more training examples (random guessing when the number of training examples is equal). Consider the differences between the cross-validation method and leave-one-out under the following two situations.
- Suppose the dataset contains 100 examples, half positive and half negative.
10-fold cross-validation: divide the dataset evenly into 10 subsets of equal size, use 9 of them as the training set and 1 as the test set, and finally take the average. Since the problem states that the model predicts the class with more training examples and guesses randomly when the number of training examples is equal, each time the training set has the same number of positive and negative examples, so the expected error rate is 50%.
Leave-one-out: if the left-out sample is positive, the training set has 50 negative and 49 positive examples, and the model will predict negative; conversely, if the left-out sample is negative, the model predicts positive, so the expected error rate is 100%.
- Suppose the dataset contains 100 examples, with 51 positive and 49 negative.
10-fold cross-validation: at this point the 10 subsets are unevenly distributed, i.e., divided into 9 subsets of 5 positives and 5 negatives and 1 subset of 6 positives and 4 negatives. When the training set has 45 positives and 45 negatives, random guessing occurs, with expected error rate ; when the training set has 46 positives and 44 negatives, it predicts positive, the test set has 5 positives and 5 negatives, with expected error rate ; in summary, the expected error rate is .
Leave-one-out: if the left-out sample is positive, the training set has 49 negatives and 50 positives, and the model will predict positive; conversely, if the left-out sample is negative, the model predicts positive, so the expected error rate is .
Neural Networks: Starting from a “Switch”
When the data relationship is very complex (highly nonlinear), polynomial fitting requires a high order and is prone to overfitting. Is there a better method?
The neural network is the answer. Its inspiration comes from the human brain: neurons connect through synapses, receiving, processing, and outputting signals. We start from the simplest “neuron”:
A neuron does three things:
- Receive input: multiply each input by a weight respectively, and add them up—this gives the pre-activation (the weighted sum before passing through the activation function).
- Activate: transform the pre-activation value through an activation function nonlinearly.
- Output: obtain the result of this neuron.
Common activation functions include sigmoid (an S-shaped curve that compresses any value into the range 01), tanh (similar to sigmoid but with output range -11), and ReLU (negative values become 0, positive values unchanged, the preferred choice for modern deep networks).
Analogy: dendrites receive input signals → cell body processes (activation) → axon outputs the result.
The simplest neural network is the perceptron—it has only a single neuron, and its activation function is a “switch”:
The modern multi-layer perceptron (MLP) stacks many such “switches” into multiple layers, where the output of each layer serves as the input of the next, passing information layer by layer until the final result is obtained. The more layers there are, the more complex the patterns that can be learned—this is the origin of the word “deep” in “deep learning”.
Chapter 1 Summary
One-sentence version:
- Error function: measures how far the model’s line is from the data points; the smaller the better.
- Overfitting: the model is too complex and treats noise as a pattern; Underfitting: the model is too simple and fails to learn the pattern.
- Regularization: adds a penalty term to the parameters to prevent the model from being too complex.
- Cross-validation: splits the data into multiple parts for training and validation in rotation, to evaluate the model fairly.
- Neural network: a bunch of simple “switches” stacked into multiple layers, capable of learning very complex patterns.
Knowledge map:
Error function → Overfitting/Underfitting → Regularization + Cross-validation ↓ Limitations of polynomial fitting → Neural Networks (MLP)In the next chapter we will learn probability theory—it is the mathematical foundation for understanding “why the error function looks like this” and “how the model makes predictions”.
Chapter 2 Probability: Reasoning Under Uncertainty
Why do we need probability? Because the real world is full of uncertainty.
There are two kinds of uncertainty:
- Aleatoric uncertainty: the data itself has noise, such as measurement instrument errors and natural fluctuations in human height—this cannot be eliminated.
- Epistemic uncertainty: because we have not collected enough data, our understanding of the pattern is incomplete—the more data, the smaller this kind of uncertainty.
Probability theory is the mathematical language for dealing with uncertainty. Many core concepts of deep learning (maximum likelihood estimation, cross-entropy, KL divergence) are built on top of probability theory.
Prerequisites: knowing what “probability” is is sufficient.
Two Schools of Thought: What Exactly Is Probability?
Starting from a coin: the probability of heads is 0.5—but what does this sentence really mean?
The frequentist view holds that probability is “the frequency with which something occurs after repeating the experiment many times”. You toss a coin 1000 times, roughly 500 heads, so the probability is 0.5. Parameters (such as the coin’s weight distribution) are fixed but unknown, and we use data to estimate them.
- Representative methods: maximum likelihood estimation (MLE), confidence intervals.
The Bayesian view holds that probability is “our degree of belief that something will happen”. Before you toss the coin, but based on experience you think it is roughly half and half—this is the prior belief; after tossing a few times, you update this belief based on the results.
- Key formula: Bayes’ theorem (explained below).
Both views have their merits and are both applied in deep learning. Frequentist methods are more common (such as maximum likelihood estimation), but Bayesian thinking is also important in regularization and uncertainty estimation.
Probability Basics: Three Iron Laws
There are only three probability rules; just remember them:
Sum rule: to know the probability that , sum the probabilities of over all possible values of :
Product rule: the probability that two events occur together = the probability that the first occurs × the probability that the second occurs given that the first has occurred:
Bayes’ theorem: this is the most important one—it tells us how to reason backward from “effect” to “cause”:
In plain words: posterior probability = (likelihood × prior) / evidence
- Prior probability : our belief about before observing .
- Posterior probability : the updated belief about after observing .
- Likelihood : the probability of observing if is true.
- Evidence : a normalization constant ensuring the probabilities sum to 1.
Example: you see the ground is wet () and want to judge whether it rained (). Prior : according to the weather forecast, the probability of rain is 30%. Likelihood : if it rained, the probability the ground is wet is 90%. Likelihood : if it did not rain, the probability the ground is wet is 10% (maybe a sprinkler truck). Posterior : after seeing the ground is wet, what is the actual probability it rained? Use Bayes’ theorem to compute it.
Independence: if two variables and do not affect each other, .
Probability Density: Probability for Continuous Variables
For discrete variables (such as dice points), each value has a definite probability. But for continuous variables (such as height, temperature), the probability of taking any exact value is 0—can you be exactly 170.000000… cm tall? Impossible.
So we introduce the probability density function (PDF) : it means the probability that falls in a small interval is approximately .
The probability that falls in the interval is the area under the density curve in that interval:
The probability density function must satisfy two conditions:
- Non-negativity: (probability cannot be negative).
- Normalization: (the total probability must be 1).
The cumulative distribution function (CDF) means “the probability that is less than or equal to ”. Its derivative is the probability density: .
The sum rule and product rule above apply equally to continuous variables, just replacing summation with integration:
- Sum rule: (integrate out the variables we do not care about).
- Product rule: .
Bayes’ theorem is likewise:
The above rules apply equally ( are two real-valued variables, multivariate/multi-dimensional):
Sum rule - when interested in only part of the variables, integrate out the other variables to obtain the distribution of the variables of interest
Product rule - when considering dependencies between variables, the joint distribution can be decomposed into the product of the conditional and marginal distributions
Bayes’ theorem
The denominator (marginal probability) can likewise be written as:
Common Probability Distributions
Before diving into deep learning, let us get to know several of the most commonly used probability distributions. You can think of them as “LEGO bricks”—many complex probabilistic models are assembled from these basic distributions.
Uniform distribution: the simplest kind—within the finite interval the probability density is equal everywhere, like pouring water evenly into a flat-bottomed container:
Exponential distribution: the probability density monotonically decreases starting from some point, often used to model “waiting time” (e.g., how long to wait for a bus):
where the larger (lambda) is, the faster the decay, indicating a higher probability of “being able to wait soon”.
Laplace distribution: looks like two exponential distributions back to back, centered at with a sharp peak. It is “sharper” than the Gaussian distribution and has “heavier” tails, making it more robust to outliers:

Red is the uniform distribution, blue is the exponential distribution, green is the Laplace distribution
The next two distributions are special; they are not ordinary “curves” but very useful tools in probability theory and statistics:
Dirac delta function: this is not an ordinary function but a kind of “generalized function”—you can imagine it as an infinitely thin, infinitely tall “needle” stuck at , but the area under this needle is exactly 1:
It is zero everywhere except at , but . It frequently appears in physics and probability theory to represent “precisely determined at some position”.
Empirical distribution: given a set of real data , the empirical distribution uses this very data itself to “approximate” the true distribution—the approach is simple: stick a δ-function “needle” at each data point , each needle having height :
In plain words: you have 10 observed data points, and the empirical distribution says “each data point has probability 1/10, and 0 everywhere else”. It is the most naive way of “letting the data speak for itself”.
Expectation and Variance
Expectation
In plain words, expectation is the theoretical version of the “weighted average”. Normally you compute the average by summing all the data and dividing by the count; expectation instead multiplies each value by the probability of its occurrence and then sums—taking into account “how likely each value is to occur”.
Discrete case: multiply each value by its corresponding probability and sum
Continuous case: replace summation with integration
Finite samples: when you only have a finite number of data points, use the empirical distribution to approximate—this is the “stick a needle at each data point” approach mentioned earlier. Specifically, using the property of the δ-function () it simplifies to:
In short: the sample mean is an approximation of the expectation. The more data, the more accurate the approximation. This is exactly the core idea of Chapter 14 - Monte Carlo approximation.
Derivation details: from empirical distribution to sample mean
Let , then , :
Therefore .
Conditional expectation: the expectation of after knowing the value of some variable —the result is a function of :
Variance
Variance measures “how spread out the data is around the expectation”—in simple terms, “how large the fluctuation is”. The larger the variance, the more dispersed the data; the smaller the variance, the more concentrated the data is around the mean.
where is the “expectation of the square” and is the “square of the expectation”—variance is the difference between the two.
The variance of the variable itself is the special case for :
Covariance
Covariance measures the “tendency of two variables to change together”. If tends to increase when increases, the covariance is positive; if one increases while the other decreases, the covariance is negative; if they do not affect each other it is 0.
If and are independent, then (note that the converse does not hold—zero covariance does not imply independence, there could be a nonlinear relationship).
Vector covariance: for vectors and , the covariance is a matrix:
The covariance matrix of the vector itself describes the correlations between its components—the diagonal holds the variances and the off-diagonal holds the covariances.
Gaussian Distribution (Normal Distribution)
The Gaussian distribution, also called the normal distribution, is the most important distribution in probability theory, bar none. Its shape is a symmetric bell curve—high in the middle, low on both sides, symmetric left and right.
Gaussian distribution → maximum likelihood estimation → derivation of the loss function for linear regression → the meaning of noise modeling
This thread runs through the next few subsections; as you read, keep this question in mind: why is the Gaussian distribution so important?
Univariate Gaussian Distribution
The formula looks intimidating, but in fact only two parameters control everything:
- (mu, mean): determines the center position of the bell curve—where the highest point of the curve is.
- (sigma squared, variance): determines the width of the bell curve—the larger is, the “fatter” and “shorter” the curve; the smaller is, the “skinnier” and “taller” the curve.
- (standard deviation): the square root of the variance, describing the same thing as the variance, but with a unit consistent with the original data.
- (precision): the reciprocal of the variance; the larger the precision, the more concentrated the distribution.
Of course, as a probability density function, it must satisfy:
Properties of the Gaussian Distribution
- Expectation (first moment): —the “center of mass” of the distribution is at the mean. For the concept of moments, see Chapter 3 - Moments.
- Second moment: .
- Variance: .
- Mode (the position of the maximum probability density): for the Gaussian distribution, the mode coincides with the mean —the highest point is right in the middle.
A Probabilistic View of Linear Regression
Remember the linear regression and error function from Chapter 1? Now we can re-understand it in the language of probability.
Model the regression problem as a conditional probability: the target value is a random variable that follows a Gaussian distribution centered at the predicted value :
where is the model’s prediction and is the noise variance.
Imagine you are predicting house prices: the input is the house area, and the model predicts as the predicted price. The actual price will not equal the predicted price exactly—it fluctuates randomly around the predicted price (because factors like school district and decoration are not accounted for).
The probabilistic view says: this fluctuation follows a Gaussian distribution. That is, the house price follows a Gaussian distribution with mean equal to the predicted value . What is the benefit? When predicting, you can output an interval (e.g., ) instead of a single isolated number—this quantifies the uncertainty.
Likelihood Function
What Is Likelihood?
Imagine you are playing a “guess the parameter” game: I give you a dataset (say, the heights of 10 people), tell you the data comes from a Gaussian distribution, but do not tell you the mean and variance. Your task is: guess a set of parameters that maximizes the probability that “this dataset occurs”.
This “probability that the data occurs” is the likelihood function. Given the parameters and , the likelihood of observing the dataset is:
You might ask: why multiply? Because we assume the data is independent and identically distributed (i.i.d.)—each data point is independently drawn from the same distribution, so the joint probability is the product of the individual probabilities.
Log-Likelihood
Multiplying is troublesome (numerically prone to overflow), so we usually take the logarithm, turning the product into a sum:
Maximum Likelihood Estimation (Maximum Likelihood, ML)
Maximum likelihood estimation (MLE) is the answer to the “guess the parameter” game—find the set of parameters that maximizes the likelihood function. The approach is: take the derivative of the likelihood function (or log-likelihood), set it to 0, and solve for the parameters.
For the Gaussian distribution, the result is surprisingly simple:
- Maximum likelihood solution for the mean : it is the sample mean
- Maximum likelihood solution for the variance : it is the sample variance
In plain words: want to know a group of people’s average height and the range of height variation? Taking the average of their heights gives , and computing the average of the squared deviations of each person from the mean gives .
Bias of Maximum Likelihood Estimation
Here is a subtle but important issue: the maximum likelihood estimate of the variance is biased.
For the Gaussian distribution:
- (the mean estimate is unbiased—exactly right)
- (the variance estimate is biased—it systematically underestimates the true variance)
Why is the variance underestimated? Imagine you are predicting height:
- If you knew the true average height, you could directly compute the variance using this value.
- But you do not—you can only use the sample mean computed from the same dataset as a substitute.
- The sample mean is computed from the same dataset, so it is naturally “closer” to this dataset than the true mean.
- Therefore the computed variance is a bit too small—this is like “grading yourself”, which always scores a bit higher than others would.
Correction method: use instead of in the denominator to obtain the unbiased variance estimator:
In short: as the amount of data increases, gets closer and closer to 1, and the bias gets smaller and smaller. But in complex models (such as neural networks), the data is often insufficient relative to the number of parameters, and the bias problem of maximum likelihood (closely related to overfitting) becomes more severe.
Maximum Likelihood Estimation = Minimizing the Sum-of-Squares Error
Remember the error function from Chapter 1? Now we can understand it from a probabilistic perspective.
When we model the regression problem with a Gaussian distribution, maximizing the likelihood function:
After taking the logarithm we obtain the log-likelihood function. The term does not depend on , so we only need to maximize:
Because is a constant, this is equivalent to minimizing the sum-of-squares error function:
This is why the sum-of-squares error is the default loss function for regression problems—it is not designed out of thin air, but is the natural result of maximum likelihood estimation when assuming the noise follows a Gaussian distribution.
In other words: the least squares method = maximum likelihood estimation under the Gaussian noise assumption.
Prediction Distribution
With the maximum likelihood estimates of the parameters, we can write out the complete prediction distribution. The maximum likelihood estimate of the noise variance is:
The prediction distribution is:
Example of predicting height:
- Input: age years
- Model prediction: cm
- Maximum likelihood estimate of the noise variance: (standard deviation cm)
- Distribution of the actual height :
- So we can expect the actual height to be roughly in the range 130~150 cm (mean standard deviations, covering about 95% of the probability)
Variable Transformation
You might ask: how does the probability density change under a variable transformation? It is not simply a matter of “replace with $y”—the transformation of probability density is different from that of ordinary functions.
Starting with Intuition: Stretching a Rubber Band
Imagine you uniformly apply ink (uniform probability density) on a rubber band. Now you stretch the rubber band to twice its original length—the ink is “diluted” and the density becomes half of the original. But the total amount of ink (probability) has not changed.
Simple example: linear transformation In -space, the length of the interval is 1; in -space it becomes , with length 2. If (in the interval ), then in the corresponding interval should be —so that the total probability is conserved:
Nonlinear Variable Transformation
For linear transformations, the scaling factor is constant. But for nonlinear transformations, the “stretching ratio” differs at every position—just like the stretching is different at different positions of the rubber band.
Consider a small interval , whose probability in -space is (remember the probability density function?).
After the transformation , this interval becomes , where . To preserve probability conservation (the probability before and after the transformation must be equal):
Therefore:
The absolute value is taken because the probability density must be non-negative. Here is the Jacobian factor—in one dimension it is just the absolute value of the derivative, representing the scaling ratio of the interval length before and after the transformation.
Univariate Transformation Formula
Let , then the probability density of the new variable is:
The Mode Position Changes!
The mode is the point where the probability density function reaches its maximum (for the Gaussian distribution it is the mean). There is an easy mistake to make here:
If we simply assume (ignoring the Jacobian factor), we would think the mode is just a coordinate transformation—the mode of is at , and after transformation the mode of is at satisfying .
But this is wrong! Because there is an extra term in the formula, its derivative introduces an additional term, causing the mode position to shift.
For example: suppose (mode at ), and apply the nonlinear transformation :
- Naive expectation: ignoring the Jacobian, think the mode is at (because ).
- Correct transformation: Due to the extra term, the position of the maximum of shifts and no longer satisfies .
This conclusion can be verified by sampling: after sampling and transforming to , the histogram of matches , not .

The result should be the red curve, not the green curve; the maxima (modes) do not match
Note: under a linear transformation, the Jacobian factor is a constant, and this problem disappears—the transformation of the mode position is as expected.
Transformation of Multivariate Distributions
Let (, are both -dimensional vectors), the transformation formula is:
where is the Jacobian matrix, with elements .
is the absolute value of the determinant of the Jacobian matrix—you can think of it as the multi-dimensional version of “rubber band stretching”: originally there is a small square in -space, which after transformation becomes an irregular quadrilateral in -space, and is the scaling factor of the area (or volume).
Variable transformation is very important in deep learning—the core idea of normalizing flow models is to progressively transform a simple distribution (such as a Gaussian distribution) into a complex distribution through a series of invertible transformations. Each transformation needs to be multiplied by the Jacobian factor.
Entropy
Information Content: A “Surprise Meter”
Imagine you are a news editor. Of the following two pieces of news, which is more “newsworthy”?
- “Tomorrow the sun rises in the east”—probability almost 100%, no surprise at all.
- “Tomorrow the sun rises in the west”—probability almost 0%, super shocking.
Intuition tells us: the less likely an event is, the more information its occurrence carries. This is the core idea of information content.
The information content function should satisfy two conditions:
- The lower the probability, the greater the information content; for an event with probability 1, the information content is 0.
- The information content of two independent events occurring together = the sum of their individual information contents (additivity).
The function satisfying these two conditions is the logarithm of the probability (the negative sign ensures non-negativity):
When the base is 2, the unit is bits.
Entropy: Average Information Content
Entropy is the expectation (average) of the information content—it measures how “uncertain” or “chaotic” a random variable is overall:
When , define (because ).
Examples:
Uniform distribution: 8 equally probable states, each with probability . Entropy bits.
Because each state is equally likely, you cannot guess at all what the next one will be—maximum uncertainty.
Non-uniform distribution: states have probabilities . Entropy bits.
Because occurs with high probability (half), you can more easily guess correctly—less uncertainty.
Source coding theorem: entropy is the lower bound on the average code length in lossless compression. In the second example, by assigning short codes to high-frequency events (e.g., a uses 0, b uses 10), the average code length can equal the entropy (2 bits).
Subsequently we use the natural logarithm (base ) to define entropy, changing the unit to nats. This is the convention in deep learning:
Differential Entropy: Entropy for Continuous Variables
Extend the concept of entropy to continuous variables—differential entropy.
Idea: bin the continuous variable with width , represent each bin by a value , with probability approximately . First compute the discrete entropy, then take the limit :
Ignoring the term that does not depend on , taking the limit gives the differential entropy:
The multivariate case is similar:
Note: unlike discrete entropy, differential entropy can be negative! This is because the “binning” process of continuous variables introduces the term; when the distribution is very concentrated (small variance), the differential entropy can be less than 0.
Maximum Entropy Distribution
Discrete case: over all possible states, the distribution with maximum entropy is the uniform distribution , at which point . The intuition is straightforward—the uniform distribution means “most uncertain”, so the entropy is maximal.
Continuous case (with constraints): without constraints, the entropy of a continuous distribution can be arbitrarily large (imagine an infinitely wide uniform distribution). So constraints usually need to be added:
- (normalization).
- (known mean).
- (known variance).
Under the constraints of a given mean and variance , the Gaussian distribution is the distribution that maximizes the differential entropy.
Derivation idea (using Lagrange multipliers + calculus of variations)
Maximize under the three constraints. Construct the Lagrangian, take the variational derivative with respect to and set it to zero, and you can get that must be the exponential of a quadratic function of —which is exactly the form of the Gaussian distribution. The specific derivation requires the use of the calculus of variations, which is beyond the scope of this chapter.
Differential Entropy of the Gaussian Distribution
The differential entropy of the Gaussian distribution has a beautiful closed-form solution:
The entropy increases as the variance increases—the “fatter” the distribution (larger variance), the greater the uncertainty, and the higher the entropy. When , the differential entropy is negative—which is impossible for discrete entropy.
KL Divergence
How “Different” Are Two Distributions?
Imagine you have two weather forecasts: one is the real weather data , and the other is your model’s prediction . You want to know: how far off is your prediction from the real situation?
The Kullback-Leibler divergence (KL divergence), also called relative entropy, is a measure of the “distance” between two probability distributions. In plain words: if you use the distribution to replace the true distribution for encoding, how much extra information is needed on average.
The first term is “the average information content of encoding with ”, and the second term is “the average information content of encoding with (i.e., the entropy)“—the KL divergence is the difference between the two.
Two Important Properties of KL Divergence
- Non-negativity: , with equality if and only if . This is easy to understand—if the two distributions are exactly the same, the “difference” is 0.
- Asymmetry: . The distance from to is different from the distance from to ! So strictly speaking, KL divergence is not a true “distance”.
Proof of non-negativity (using Jensen's inequality)
Convex function: a function is convex if any chord lies above the function’s graph, i.e., .
Jensen’s inequality: for a convex function and a probability distribution : In plain words: the expectation of the function ≥ the function of the expectation (for a convex function).
is a strictly convex function. Let , then:
The Relationship Between KL Divergence and Maximum Likelihood Estimation
Minimizing KL divergence is equivalent to maximizing the likelihood function—this is a key bridge connecting probability theory and machine learning.
In theory:
In practice, we have samples from the true distribution , which can be approximated as:
The second term is constant (because is the true distribution, independent of the model parameters ), so minimizing KL divergence is equivalent to minimizing the first term—that is, maximizing —that is, maximizing the likelihood function.
In short: minimizing KL divergence when training a model is doing maximum likelihood estimation. This explains why maximum likelihood estimation is such a natural and prevalent method.
Conditional Entropy
Conditional entropy measures: after knowing the variable , how much average information is still needed to describe the variable .
Weather forecast example:
- : today’s weather (sunny/rainy)
- : tomorrow’s weather
- (unconditional entropy): how uncertain is predicting tomorrow’s weather without looking at today’s weather
- (conditional entropy): how uncertain is predicting tomorrow’s weather after seeing today’s weather
Clearly , because today’s weather provides useful information—knowing it rained today makes it easier to predict it will rain tomorrow too.
Between conditional entropy, joint entropy, and marginal entropy there is an elegant chain rule:
In plain words: the total information content of and = the information content of describing + the additional information content of describing given .
Mutual Information
Mutual information measures “how much information is shared” between two variables—or, how much knowing one variable can reduce your uncertainty about the other.
Mathematically, mutual information is the KL divergence between the joint distribution and the distribution assuming they are independent:
- If and are independent: , the KL divergence is 0, and the mutual information is 0—knowing is of no help in predicting .
- If and are correlated: , the mutual information is greater than 0—knowing helps you predict better.
The relationship between mutual information and entropy is very intuitive:
Weather forecast example (continued):
- : the uncertainty of predicting today’s weather (say 2 bits)
- : the uncertainty of predicting today’s weather after knowing tomorrow’s weather (say 0.5 bits)
- bits
These 1.5 bits are the information shared between today’s and tomorrow’s weather—knowing tomorrow’s weather, you “for free” obtain 1.5 bits of information about today’s weather.
From a Bayesian perspective, is the prior distribution (our understanding of before observing ), and is the posterior distribution (our understanding of after observing ). Mutual information is exactly the reduction in uncertainty—after observing , by how much has your uncertainty about decreased.
Mutual information has many applications in deep learning, such as feature selection (selecting features with the greatest mutual information with the target variable), the information bottleneck theory, etc.
Chapter 2 Summary
One-sentence version:
- Probability basics: probability theory has only three rules—the sum rule, the product rule, and Bayes’ theorem. Bayes’ theorem tells us how to update our beliefs using observations.
- Common distributions: the uniform, exponential, and Laplace distributions are basic building blocks; the Dirac delta function and empirical distribution are special tools.
- Expectation and variance: expectation = the theoretical version of the average; variance = how large the fluctuation is; covariance = the tendency of two variables to change together.
- Gaussian distribution: the most important continuous distribution, a bell curve, determined solely by two parameters—the mean and the variance. When assuming the noise follows a Gaussian distribution, maximum likelihood estimation = the least squares method.
- Likelihood function: the probability that the data occurs given the parameters. Maximum likelihood estimation finds the parameters that “most likely produced this dataset”.
- Variable transformation: when transforming the probability density, multiply by the Jacobian factor (the scaling ratio of “rubber band stretching”).
- Entropy: a measure of uncertainty. A “surprise meter”—the less likely an event, the more information its occurrence carries.
- KL divergence: the “difference” between two distributions. Non-negative and asymmetric. Minimizing KL divergence = maximizing the likelihood function.
- Conditional entropy and mutual information: conditional entropy = the remaining uncertainty after knowing one variable; mutual information = the information shared between two variables.
Knowledge map:
Probability basics (sum/product/Bayes) ├── Common distributions (uniform/exponential/Laplace/Dirac delta/empirical) ├── Expectation, variance, covariance ├── Gaussian distribution (bell curve) │ ├── Maximum likelihood estimation (MLE) │ │ ├── Mean → sample mean │ │ ├── Variance → sample variance (biased → unbiased correction) │ │ └── Equivalent to minimizing sum-of-squares error (error function of Chapter 1) │ └── Prediction distribution (outputs an interval rather than a point estimate) ├── Variable transformation (Jacobian factor → foundation of normalizing flows) └── Information theory ├── Entropy (uncertainty measure) ├── KL divergence (distribution difference → theoretical basis of model training) ├── Conditional entropy (remaining uncertainty after knowing one variable) └── Mutual information (information shared between variables)In the next chapter we will learn the estimation methods of probabilistic models—how to use data to fit distributions and make predictions.