第 24 章 · 概率
Understanding Deep Learning — Probability
Probability is critical to deep learning. In supervised learning, deep networks implicitly rely on a probabilistic formulation of the loss function. In unsupervised learning, generative models aim to produce samples that are drawn from the same probability distribution as the training data. Reinforcement learning occurs within Markov decision processes, and these are defined in terms of probability distributions. This appendix provides a primer for probability as used in machine learning.
概率对深度学习至关重要。在监督学习中,深度网络隐式依赖于损失函数的概率化表述。在无监督学习中,生成模型旨在产生与训练数据来自同一概率分布的样本。强化学习发生在马尔可夫决策过程之中,而这些过程由概率分布来定义。本附录为机器学习中使用的概率提供入门介绍。
Arandomvariablex denotes a quantity that is uncertain. It may be discrete (take only certain values, for example integers) or continuous (take any value on a continuum, for example real numbers). If we observe several instances of a random variable x, it will take different values, and the relative propensity to take different values is described by a probabilitydistributionPr(x).
For a discrete variable, this distribution associates a probability Pr(x=k) ∈[0, 1] with each potential outcome k, and the sum of these probabilities is one. For a continuous variable, there is a non-negative probabilitydensityPr(x = a)≥0 associated with each value a in the domain of x, and the integral of this probability density function (PDF) over this domain must be one. This density can be greater than one for any point a. From here on, we assume that the random variables are continuous. The ideas are exactly the same for discrete distributions but with sums replacing integrals.
随机变量 x 表示一个不确定的量。它可以是离散(只取某些值,例如整数)或连续(在连续统上取任意值,例如实数)。如果我们观察随机变量 x 的多个实例,它将取不同的值,而取不同值的相对倾向由概率分布 Pr (x)描述。
对于离散变量,该分布将概率 Pr (x=k) ∈[0, 1] 与每个可能结果 k 相关联,且这些概率之和为 1。对于连续变量,存在一个非负的概率密度 Pr (x = a) ≥0 与 x 定义域中的每个值 a 相关联,并且该概率密度函数(PDF)在该定义域上的积分必须为 1。该密度在任意点 a 都可能大于 1。以下我们假设随机变量是连续的。对于离散分布,思想完全相同,只是用求和代替积分。
Consider the case where we have two random variables x and y. The jointdistribu- tionPr(x, y) tells us about the propensity that x and y take particular combinations of values (figure C.1a). Now there is a non-negative probability density Pr(x = a, y = b) associated with each pair of values x = a and y= b and this must satisfy: (C.1)
考虑我们有两个随机变量 x 和 y 的情况。联合分布 Pr (x, y) 说明了 x 和 y 取特定取值组合的倾向(图 C.1a)。现在,有一个非负概率密度 Pr (x = a, y = b) 与每一对取值 x = a 和 y= b 相关联,且必须满足: (C.1)

This idea extends to more than two variables, so the joint density of x, y, and z is written as Pr(x, y, z). Sometimes, we store multiple random variables in a vector x, and we write their joint density as Pr( x ). Extending this, we can write the joint density of all of the variables in two vectors x and y as Pr( x , y ).
这一思想可以推广到两个以上的变量,因此 x, y 和 z 的联合密度写作 Pr (x, y, z)。有时,我们将多个随机变量存储在一个向量 x 中,并将其联合密度写作 Pr (x)。进一步推广,我们可以将两个向量 x 和 y 中所有变量的联合密度写作 Pr (x , y)。
If we know the joint distribution Pr(x, y) over two variables, we can recover the marginal distributions Pr(x) and Pr(y) by integrating over the other variable (figure C.1b-c): (C.2)
如果我们知道两个变量的联合分布 Pr (x, y),就可以通过对另一个变量积分得到边缘分布 Pr (x) 和 Pr (y) (图 C.1b-c): (C.2)
This process is called marginalization and has the interpretation that we are computing the distribution of one variable regardless of the value the other one took.
The idea of marginalization extends to higher dimensions, so if we have a joint distribution Pr(x, y, z), we can recover the joint distribution Pr(x, z) by integrating over y.
这一过程称为边缘化,其含义是我们在计算一个变量的分布时,无论另一个变量取何值。边缘化的思想可以推广到更高维,因此如果我们有一个联合分布 Pr (x, y, z),就可以通过对 y 积分得到联合分布 Pr (x, z)。
The conditional probability Pr(x|y) is the probability of variable x taking a certain value, assuming we know the value of y. The vertical line is read as the English word “given,”
条件概率 Pr (x|y) 是在已知 y 取值的情况下,变量 x 取某一值的概率。竖线读作英文单词“given,”

so Pr(x|y) is the probability of x given y. The conditional probability Pr(x|y) can be found by taking a slice through the joint distribution Pr(x, y) for a fixed y. This slice is then divided by the probability of that value y occurring (the total area under the slice) so that the conditional distribution sums to one (figure C.2): (C.3) Similarly, (C.4)
When we consider the conditional probability Pr(x|y) as a function of x, it must sum to one. When we consider the same quantity Pr(x|y) as a function of y, it is termed the likelihood of x given y and does not have to sum to one.
因此, Pr (x|y) 是在给定 y 的条件下 x 的概率。条件概率 Pr (x|y) 可通过在固定 y 处对联合分布 Pr (x, y) 取一个切片来求得。然后将该切片除以该值 y 出现的概率(切片下的总面积),使条件分布的总和为 1 (图 C.2): (C.3)类似地, (C.4)
当我们把条件概率 Pr (x|y) 视为 x 的函数时,它必须总和为 1。当我们把同一量 Pr (x|y) 视为 y 的函数时,它被称为 x 在给定 y 时的似然,并且不必总和为 1。
From equations C.3 and C.4, we get two expressions for the joint probability Pr(x, y): (C.5)
which we can rearrange to get: (C.6)
F 由公式 C.3 和 C.4,我们得到联合概率 Pr (x, y) 的两个表达式:
(C.5) 我们可以将其重新排列,得到: (C.6)

This expression relates the conditional probability Pr(x|y) of x given y to the conditional probability Pr(y|x) of y given x and is known as Bayes’rule.
Each term in this Bayes’ rule has a name. The term Pr(y|x) is the likelihood of y given x, and the term Pr(x) is the priorprobability of x. The denominator Pr(y) is known as the evidence, and the left-hand side Pr(x|y) is termed the posteriorprobability of x given y. The equation maps from the prior Pr(x) (what we know about x before observing y) to the posterior Pr(x|y) (what we know about x after observing y).
该贝叶斯公式中的每一项都有名称。项 Pr (y|x) 是在给定 x 条件下 y 的似然,而项 Pr (x) 是 x 的先验概率。分母 Pr (y) 被称为证据,等式左侧 Pr (x|y) 称为在给定 y 条件下 x 的后验概率。该公式将先验 Pr (x) (在观测 y 之前我们对 x 的了解)映射到后验 Pr (x|y) (在观测 y 之后我们对 x 的了解)。
If the value of the random variable y tells us nothing about x and vice-versa, we say that x and y are independent, and we can write Pr(x|y) = Pr(x) and Pr(y|x) = Pr(y). It follows that all of the conditional distributions Pr(y|x = •) are identical, as are the conditional distributions Pr(x|y=•).
Starting from the first expression for the joint probability in equation C.5, we see that the joint distribution becomes the product of the marginal distributions: (C.7)
如果随机变量 y 的取值不能告诉我们关于 x 的任何信息,反之亦然,我们就说 x 和 y 是独立的,并且可以写成 Pr (x|y) = Pr (x) 和 Pr (y|x) = Pr (y)。由此可知,所有条件分布 Pr (y|x = •) 都相同,条件分布 Pr (x|y=•) 也相同。
从式 C.5 中联合概率的第一个表达式出发,我们发现联合分布变为边缘分布的乘积: (C.7)
when the variables are independent (figure C.3).
当变量相互独立时(图 C.3)。
Consider a function f[x] and a probability distribution Pr(x) defined over x. The ex- pectedvalue of a function f[•] of a random variable x with respect to the probability distribution Pr(x) is defined as: (C.8)
As the name suggests, this is the expected or average value of f[x] after taking into account the probability of seeing different values of x. This idea generalizes to functions f[•, •] of more than one random variable: (C.9)
考虑一个函数 f[x] 和一个定义在 x 上的概率分布 Pr (x)。随机变量 x 的函数 f[•] 相对于概率分布 Pr (x) 的期望值定义为: (C.8)
顾名思义, f[x] 的期望值或平均值是在考虑 x 出现不同取值的概率后得到的。这一思想可以推广到多个随机变量的函数 f[•, •]: (C.9)
An expectation is always taken with respect to a distribution over one or more variables. However, we don’t usually make this explicit when the choice of distribution is obvious and write E[ f[x]] instead of Ex[ f[x]]. If we drew a large number I of samples{xi}I
i=1 from Pr(x), calculated f[xi] for each sample and took the average of these values, the result would approximate the expectation E[ f[x]] of the function: (C.10)
期望总是相对于一个或多个变量的分布而言的。不过,当分布的选择显而易见时,我们通常不会明确写出这一点,而是写 E[ f[x]],而不是 Ex[ f[x]]。如果我们抽取大量 I 个样本{xi}I
i=1,它们来自 Pr (x),计算每个样本的 f[xi],并对这些值取平均,那么结果将近似于该函数的期望 E[ f[x]]: (C.10)
There are four rules for manipulating expectations: if x, y independent , (C.11)
where k is an arbitrary constant. These are proven below for the continuous case.
期望运算有四条规则: if x, y independent ,
(C.11) 其中 k 是任意常数。以下针对连续情形证明这些规则。
Rule 1:
The expectation E[k] of a constant value k is just k. (C.12)
规则 1:常数值 k 的期望 E[k] 就是 k。 (C.12)
Rule 2:
The expectation E[k · f[x]] of a constant k times a function of the variable x is k times the expectation E[ f[x]] of the function: (C.13)
规则 2:对于常数 k 乘以变量 x 的函数,其期望 E[k · f[x]] 等于 k 乘以该函数的期望 E[ f[x]]: (C.13)
Rule 3:
The expectation of a sum E[ f[x] + g[x]] of terms is the sum E[ f[x]] + E[ g[x]] of the expectations: (C.14)
规则 3:各项之和 E[ f[x] + g[x]] 的期望等于期望之和 E[ f[x]] + E[ g[x]]: (C.14)
Rule 4:
The expectation of a product E[ f[x]· g[y]] of terms is the product E[ f[x]]·E[ g[y]] if x and y are independent. (C.15)
规则 4:各项之积 E[ f[x]· g[y]] 的期望等于 E[ f[x]]·E[ g[y]] 之积,当 x 与 y 相互独立时。 (C.15)
where we used the definition of independence (equation C.7) between the first two lines.
The four rules generalize to the multivariate case: if x , y independent , (C.16)
其中,我们在前两行之间使用了独立性的定义(公式 C.7)。这四条规则可推广到多元情形: if x , y independent , (C.16)
where now A is a constant matrix and f[ x ] is a function of the vector x that returns a vector, and g[ y ] is a function of the vector y that also returns a vector.
其中,现在 A 是一个常数矩阵, f[ x ] 是一个以向量 x 为输入、返回一个向量的函数,而 g[ y ] 是一个以向量 y 为输入、同样返回一个向量的函数。
For some choices of function f[•], the expectation is given a special name. These quantities are often used to summarize the properties of complex distributions. For example, when f[x]=x, the resulting expectation E[x] is termed the mean, µ.
It is a measure of the center of a distribution. Similarly, the expected squared deviation from the mean E[(x −µ)2] is termed the variance, σ2. This is a measure of the spread of the distribution. The standarddeviationσ is the positive square root of the variance. It also measures the spread of the distribution but has the merit that it is expressed in the same units as the variable x.
对于函数 f[•] 的某些选择,期望会被赋予一个特殊名称。这些量常用于概括复杂分布的性质。例如,当 f[x]=x 时,所得的期望 E[x] 称为均值, µ。它是分布中心的度量。同样,相对于均值的平方偏差的期望 E[ (x −µ) 2] 称为方差, σ2。它是分布离散程度的度量。标准差 σ 是方差的正平方根。它同样衡量分布的离散程度,但优点在于其单位与变量 x 相同。
As the name suggests, the covarianceE[(x −µx)(y −µy)] of two variables x and y measures the degree to which they co-vary. Here µx and µy represent the mean of the variables x and y, respectively. The covariance will be large when the variance of both variables is large and when the value of x tends to increase when the value of y increases.
If two variables are independent, then their covariance is zero. However, a covariance of zero does not imply independence. For example, consider a distribution Pr(x, y) where the probability is uniformly distributed on a circle of radius one centered on the origin of the x, y plane. There is no tendency on average for x to increase when y increases or vice-versa. However, knowing the value of x=0 tells us that y has an equal chance of taking the values ±1, so the variables cannot be independent.
The covariances of multiple random variables stored in a column vector x ∈RD can be represented by the D×DcovariancematrixE[( x −µx)( x −µx)T], where the vector µx contains the means E[ x ]. The element at position(i, j) of this matrix represents the covariance between variables xi and xj.
顾名思义,协方差 E[ (x −µx)(y −µy) ] 衡量两个变量 x 和 y 共同变化的程度。这里, µx 和 µy 分别表示变量 x 和 y 的均值。当两个变量的方差都较大,并且当 x 的值倾向于随 y 的值增大而增大时,协方差就会较大。
如果两个变量相互独立,则它们的协方差为零。然而,协方差为零并不意味着相互独立。例如,考虑一个分布 Pr (x, y),其中概率均匀分布在以 x,y 平面的原点为中心、半径为 1 的圆上。平均而言,当 y 增大时, x 并没有增大的趋势,反之亦然。然而,知道 x=0 的取值会告诉我们, y 取 ±1 中各个值的概率相等,因此这些变量不可能相互独立。
存储于列向量 x ∈RD 中的多个随机变量的协方差可由 D×D 协方差矩阵 E[ (x −µx)(x −µx) T] 表示,其中向量 µx 包含均值 E[ x ]。该矩阵在位置 (i, j) 处的元素表示变量 xi 和 xj 之间的协方差。
The rules of expectation (appendix C.2.1) can be used to prove the following identity that allows us to write the variance in a different form: (C.17)
(C.17)
Proof: (C.18)
where we have used rule 3 between lines one and two, rules 1 and 2 between lines two and three, and the definition µ = E[x] in lines four and six.
证明: (C.18)
其中,我们在第一行和第二行之间使用了规则 3,在第二行和第三行之间使用了规则 1 和规则 2,并在第四行和第六行中使用了定义 µ = E[x]。
Setting the mean of a random variable to zero and the variance to one is known as standardization. This is achieved using the transformation: (C.19)
where µ is the mean of x and σ is the standard deviation.
将随机变量的均值设为零、方差设为一,称为标准化。这可以通过以下变换实现: (C.19)
其中 µ 是 x 的均值, σ 是标准差。
Proof:
The mean of the new distribution over z is given by: (C.20)
证明:关于 z 的新分布的均值由下式给出: (C.20)
where again, we have used the four rules for manipulating expectations. The variance of the new distribution is given by: (C.21)
By a similar argument, we can take a standardized variable z with mean zero and unit variance and convert it to a variable x with mean µ and variance σ2 using: (C.22)
这里我们再次使用了期望的四个运算规则。新分布的方差由下式给出: (C.21)
通过类似的论证,我们可以取一个均值为零、方差为 1 的标准化变量 z,并使用下式将其转换为均值为 µ、方差为 σ2 的变量 x: (C.22)在多变量情形下,我们可以对均值为 µ 的变量 x 进行标准化,其协方差
In the multivariate case, we can standardize a variable x with mean µ and covariance matrix Σ using: (C.23)
The result will have a mean E[ z ] = 0 and an identity covariance matrix E[( z −E[ z ])( z − E[ z ])T] = I. To reverse this process, we use: (C.24)
e 矩阵 Σ 采用:
(C.23) 结果将具有均值 E[ z ] = 0 和单位协方差矩阵 E[ (z −E[ z ])(z −E[ z ]) T] = I。要逆转这一过程,我们使用: (C.24)
Probability distributions used in this book include the Bernoulli distribution (figure 5.6), categorical distribution (figure 5.9), Poisson distribution (figure 5.15), von Mises distribution (figure 5.13), and mixture of Gaussians (figures 5.14 and 17.1). However, the most common distribution in machine learning is the normal or Gaussian distribution.
本书中使用的概率分布包括伯努利分布(图 5.6)、类别分布(图 5.9)、泊松分布(图 5.15)、冯 · 米塞斯分布(图 5.13)以及高斯混合分布(图 5.14 和 17.1)。然而,机器学习中最常见的分布是正态分布或高斯分布。
A univariate normal distribution (figure 5.3) over scalar variable x has two parameters, the mean µ and the variance σ2, and is defined as: (C.25)
A 定义在标量变量 x 上的一元正态分布(图 5.3)有两个参数

th 均值 µ 和方差 σ2,定义为: (C.25)
Unsurprisingly, the mean E[x] of a normally distributed variable is given by the mean parameter µ and the variance E[(x −E[x])2] by the variance parameter σ2. When the mean is zero and the variance is one, we refer to this as a standard normal distribution. The shape of the normal distribution can be inferred from the following argument. The term −(x−µ)2/2σ2 is a quadratic function that falls away from zero when x = µ at a rate that increases when σ becomes smaller. When we pass this through the exponential function (figure B.1), we get a bell-shaped curve, which has a value of one at x=µ
2πσ2 ensures that the function and falls away to either side. Dividing by the constant integrates to one and is a valid distribution.
不出所料,服从正态分布的变量的均值 E[x] 由均值参数 µ 给出,而方差 E[ (x −E[x]) 2] 由方差参数 σ2 给出。当均值为零且方差为一时,我们称之为标准正态分布。正态分布的形状可以从以下论证中推断出来。项 − (x−µ) 2/2σ2 是一个二次函数,当 x = µ 时,它从零开始下降,且当 σ 变小时下降速率增大。当我们把它通过指数函数(图 B.1)时,会得到一条钟形曲线,它在 x=µ 处的值为 1,并向两侧衰减。除以常
2πσ2 可确保该函数的积分为 1,从而是一个有效的分布。由该论证可知,均值 µ 控数制钟形曲线中心的位置,方差的平方根 σ (标准差)控制钟形曲线的宽度。

It follows from this argument that the mean µ control the position of the center of the bell curve, and the square root σ of the variance (the standard deviation) controls the width of the bell curve.
The multivariate normal distribution generalizes the normal distribution to describe the probability over a vector quantity x of length D. It is defined by a D × 1meanvectorµ and a symmetric positive definite D × Dcovariancematrix Σ: (C.26)
The interpretation is similar to the univariate case. The quadratic term −( x −µ)T Σ −1( x − µ)/2 returns a scalar that decreases as x grows further from the mean µ, at a rate that depends on the matrix Σ. This is turned into a bell-curve shape by the exponential, and dividing by(2π)D/2|Σ|1/2 ensures that the distribution integrates to one.
多元正态分布将正态分布推广,用于描述向量 x 上的概率,该向量的长度为 D。它由 D × 1 均值向量 µ 和一个对称正定的 D × D 协方差矩阵 Σ 定义: (C.26)
解释与单变量情形类似。二次项 − (x −µ) T Σ −1 (x −µ) /2 回报一个标量,该标量会随着 x 离均值 µ 越来越远而减小,其减小速率取决于矩阵 Σ。指数函数将其转换为钟形曲线,而除以 (2π) D/2|Σ|1/2 可确保该分布的积分为一。
The covariance matrix can take spherical, diagonal, and full forms: (C.27)
协方差矩阵可以取球形、对角和满形式: (C.27)

In two dimensions (figure C.4), spherical covariances produce circular iso-density contours, and diagonal covariances produce ellipsoidal iso-contours that are aligned with the coordinate axes. Full covariances produce general ellipsoidal iso-density contours. When the covariance is spherical or diagonal, the individual variables are independent: (C.28)
在二维情况下(图 C.4),球形协方差产生圆形等密度轮廓,对角协方差产生与坐标轴对齐的椭圆等密度轮廓。满协方差产生一般的椭圆等密度轮廓。当协方差为球形或对角时,各个变量是独立的: (C.28)

The product of two normal distributions is proportional to a third normal distribution according to the relation: Norm x[ a , A ] Norm x[ b , B ] ∝ Norm x
根据以下关系,两个正态分布的乘积与第三个正态分布成正比: Norm x[ a , A ] Norm x[ b , B ] ∝ Norm x

(C.29) This is easily proved by multiplying out the exponential terms and completing the square (see problem 18.5).
(C.29) 通过展开指数项并配方即可轻松证明(见习题 18.5)。
When the mean of a multivariate normal in x is a linear function Ay + b of a second variable y, this is proportional to another normal distribution in y, where the mean is a linear function of x: (C.30)
当关于 x 的多元正态分布的均值是第二个变量 y 的线性函数 Ay + b 时,这与关于 y 的另一个正态分布成正比,其中均值是关于 x 的线性函数: (C.30)
At first sight, this relation is rather opaque, but figure C.5 shows the case for scalar x and y, which is easy to understand. As for the previous relation, this can be proved by expanding the quadratic product in the exponential term and completing the square to make this a distribution in y. (see problem 18.4).
乍看之下,这个关系相当晦涩,但图 C.5 展示了标量 x 和 y 的情形,这很容易理解。对于前面的关系,可以通过展开指数项中的二次乘积并配方,使其成为关于 y 的分布来证明。(见习题 18.4)。
To sample from a univariate distribution Pr(x), we first compute the cumulative distribution F[x] (the integral of Pr(x)). Then we draw a sample z∗ from a uniform distribution over the range[0, 1] and evaluate this against the inverse of the cumulative distribution, so the sample x∗ is created as: (C.31)
要从单变量分布 Pr (x) 中采样,我们首先计算累积分布 F[x] (即 Pr (x) 的积分)。然后从范围 [0, 1] 上的均匀分布中抽取样本 z∗,并将其代入累积分布的逆函数,因此样本 x∗ 的生成方式为: (C.31)
The method above can be used to generate a sample x∗ from a univariate standard normal distribution. A sample from a normal distribution with mean µ and variance σ2 can then be created using equation C.22. Similarly, a sample x ∗ from a D-dimensional multivariate standard distribution can be created by independently sampling D univariate standard normal variables. A sample from a multivariate normal distribution with mean µ and covariance Σ can be then created using equation C.24.
上述方法可用于生成来自一元标准正态分布的样本 x∗。然后,可以使用公式 C.22 创建来自均值为 µ、方差为 σ2 的正态分布的样本。类似地,可以通过独立采样 D 个一元标准正态变量来创建来自 D 维多元标准正态分布的样本 x ∗。然后,可以使用公式 C.24 创建来自均值为 µ、协方差为 Σ 的多元正态分布的样本。
When the joint distribution can be factored into a series of conditional probabilities, we can generate samples using ancestral sampling. The basic idea is to generate a sample from the root variable(s) and then sample from the subsequent conditional distributions based on this instantiation. This process is known as ancestral sampling and is easiest to understand with an example.
Consider a joint distribution Pr(x, y, z) over three variables, x, y, and z, which (in this particular case) factors as: (C.32)
To sample from this joint distribution, we first draw a sample x∗ from Pr(x). Then we draw a sample y∗ from Pr(y|x∗). Finally, we draw a sample z∗ from Pr(z|y∗).
当联合分布可以分解为一系列条件概率时,我们可以使用祖先采样生成样本。基本思想是先生成根变量(或多个根变量)的样本,然后基于该实例化从后续条件分布中采样。这一过程称为祖先采样,用示例来理解最为容易。考虑一个联合分布 Pr (x, y, z),它涉及三个变量 x, y 和 z,(在这种特定情况下)它可以分解为:
(C.32) 为了从该联合分布中采样,我们首先从 Pr (x) 中抽取样本 x∗。然后从 Pr (y|x∗) 中抽取样本 y∗。最后从 Pr (z|y∗) 中抽取样本 z∗。
Supervised learning can be framed in terms of minimizing the distance between the probability distribution implied by the model and the discrete probability distribution implied by the samples (section 5.7).
Unsupervised learning can often be framed in terms of minimizing the distance between the probability distribution of real examples and the distribution of data from the model. In both cases, we need a measure of distance between two probability distributions. This section considers the properties of several different measures of distance between distributions (see also figure 15.8 for a discussion of the Wasserstein or earth mover’s distance).
监督学习可以表述为最小化模型所隐含的概率分布与样本所隐含的离散概率分布之间的距离(第 5.7 节)。无监督学习通常可以表述为最小化真实示例的概率分布与来自模型的数据分布之间的距离。在这两种情况下,我们都需要一种衡量两个概率分布之间距离的度量。本节讨论几种不同分布间距离度量的性质(另见图 15.8,其中讨论了 Wasserstein 距离或推土机距离)。
![图 C.6 负对数的下界。函数1 −y 始终小于函数−log[y]。这一关系用于证明 Kullback-Leibler散度始终大于或等于零。](/learning/udl/ch24/figures/ch24_p13_f0.webp)
The most common measure of distance between probability distributions p(x) and q(x) is the Kullback-Leibler or KL divergence and is defined as: (C.33)
概率分布 p (x) 与 q (x) 之间最常见的距离度量是 Kullback-Leibler 散度或 KL 散度,其定义为: (C.33)
This distance is always greater than or equal to zero, which is easily demonstrated by noting that −log[y] ≥1 −y (figure C.6) so: (C.34)
The KL divergence is infinite if there are places where q(x) is zero but p(x) is non-zero. This can lead to problems when we are minimizing a function based on this distance.
该距离始终大于或等于零,这很容易通过注意到 − log[y] ≥1 −y (图 C.6)来证明,因此: (C.34) T 如果存在某些位置使得 q (x) 为零但 p (x) 非零,则 KL 散度为无穷大

T 当我们在最小化基于该距离的函数时,这可能会导致问题。
The KL divergence is not symmetric (i.e., DKL[p(x)||q(x)]̸=DKL[q(x)||p(x)]).
The Jensen-Shannon divergence is a measure of distance that is symmetric by construction: (C.35)
KL 散度不是对称的(即, DKL[p (x) ||q (x) ]̸=DKL[q (x) ||p (x) ])。杰森 - 香农散度是一种在构造上对称的距离度量: (C.35)
It is the mean divergence of p(x) and q(x) to the average of the two distributions.
这是 p (x) 和 q (x) 相对于两个分布平均值的平均散度。
The Fréchet distance DF r between two distributions p(x) and q(x) is given by: (C.36)
where π(x, y) represents the set of joint distributions that are compatible with the marginal distributions p(x) and q(y). The Fréchet distance can also be formulated as a measure of the maximum distance between the cumulative probability curves.
两个分布 p (x) 和 q (x) 之间的 Fréchet 距离 DF r 由下式给出: (C.36)
其中 π (x, y) 表示与边缘分布 p (x) 和 q (y) 相容的联合分布集合。弗雷歇距离也可以表述为累积概率曲线之间最大距离的度量。
Often we want to compute the distance between two multivariate normal distributions with means µ1 and µ2 and covariances Σ 1 and Σ 2. In this case, various measures of distance can be written in closed form.
The KL divergence can be computed as:
通常,我们想要计算均值为 µ1 和 µ2、协方差为 Σ 1 和 Σ 2 的两个多元正态分布之间的距离。在这种情况下,各种距离度量都可以写成闭式形式。
KL 散度可以计算如下:
where tr[•] is the trace of the matrix argument. The Fréchet/2-Wasserstein distance is given by: (C.38)
其中 tr[•] 是矩阵参数的迹。 Fréchet/2-Wasserstein 距离由下式给出: (C.38)
