学习资料 理解深度学习 第 5 章 · 损失函数
学 习 资 料 · 中 英 对 照

第 5 章 · 损失函数

Understanding Deep Learning — Loss functions

损失函数
Loss functions

The last three chapters described linear regression, shallow neural networks, and deep neural networks. Each represents a family of functions that map input to output, where the particular member of the family is determined by the model parameters ϕ. When we train these models, we seek the parameters that produce the best possible mapping from input to output for the task we are considering. This chapter defines what is meant by the “best possible” mapping.

That definition requires a training dataset{ x i, y i} of input/output pairs.

A loss function or costfunctionL[ϕ] returns a single number that describes the mismatch between the model predictions f[ x i, ϕ] and their corresponding ground-truth outputs y i. During training, we seek parameter values ϕ that minimize the loss and hence map the training inputs to the outputs as closely as possible. We saw one example of a loss function in chapter 2; the least squares loss function is suitable for univariate regression problems for which the target is a real number y∈R. It computes the sum of the squares

前三章介绍了线性回归、浅层神经网络和深层神经网络。每一种都代表一族函数,将输入映射到输出,其中该族中的特定成员由模型参数 ϕ 决定。在训练这些模型时,我们寻找针对所考虑任务能够产生从输入到输出的最佳可能映射的参数。本章定义了“最佳可能”映射的含义。该定义需要一个训练数据集{ x i, y i} 输入 / 输出对。一个损失函数或成本函数 L[ϕ] 返回一个描述模型预测 f[ x i, ϕ] 与其对应真实输出 y i 之间的差异的单个数值。在训练期间,我们寻找参数值 ϕ 以最小化损失,从而尽可能将训练输入映射到输出。我们在第 2 章中看到了一个损失函数的示例;最小二乘损失函数适用于目标为实数 y∈R。它计算平方和

of the deviations between the model predictions f[ x i, ϕ] and the true values yi.

模型预测 f[ x i, ϕ] 与真实值 yi 之间偏差的。

This chapter provides a framework that both justifies the choice of the least squares criterion for real-valued outputs and allows us to build loss functions for other prediction types. We consider binaryclassification, where the prediction y∈{0, 1} is one of two categories, multiclassclassification, where the prediction y∈{1, 2,..., K} is one of K categories, and more complex cases. In the following two chapters, we address model training, where the goal is to find the parameter values that minimize these loss functions.

本章提供了一个框架,既论证了为实值输出选择最小二乘准则的合理性,又允许我们为其他预测类型构建损失函数。我们考虑二分类,其中预测 y∈{0, 1} 是两类中的一类,多分类,其中预测 y∈{1, 2,..., K} 是 K 类中的一类,以及更复杂的情况。在接下来的两章中,我们将讨论模型训练,其目标是找到最小化这些损失函数的参数值。

5.1 极大似然
5.1 Maximum likelihood

In this section, we develop a recipe for constructing loss functions. Consider a model f[ x , ϕ] with parameters ϕ that computes an output from input x. Until now, we have implied that the model directly computes a prediction y. We now shift perspective and consider the model as computing a conditional probability distribution Pr( y | x ) over

已经暗示模型直接计算预测 y。我们现在转换视角,将模型视为计算一个条件概率分布

possible outputs y given input x. The loss encourages each training output y i to have a high probability under the distribution Pr( y i| x i) computed from the corresponding input x i (figure 5.1).

Pr( y | x ),该分布覆盖可能的输出 y (在给定输入 x 下)。损失函数鼓励每个训练输出 y i 在分布 Pr( y i| x i) 下具有较高的概率。该分布由对应的输入 x i 计算得到(图 5.1)。

图 5.1 预测输出的分布。 a) 回归任务,目标是根据训练数据 {xi, yi} (橙色点)从输入 x 预测实值输出 y。对于每个输入值 x,机器学习模型预测
图 5.1 预测输出的分布。 a) 回归任务,目标是根据训练数据 {xi, yi} (橙色点)从输入 x 预测实值输出 y。对于每个输入值 x,机器学习模型预测输出 y∈R 上的分布 Pr (y|x) (青色曲线显示 x=2.0 和 x=7.0 的分布)。最小化损失函数相当于最大化在根据相应输入 xi 预测的分布下训练输出 yi 的概率。 b) 为了在分类任务中预测离散类别 y∈{1, 2, 3, 4},我们使用离散概率分布,因此模型针对 xi 的每个值预测 yi 的四个可能值上的不同直方图。 c) 为了预测计数 y∈{0, 1, 2,...}, d) 方向 y∈ (−π, π],我们分别使用定义在正整数和圆形域上的分布。Figure 5.1 Predicting distributions over outputs. a) Regression task, where the goal is to predict a real-valued output y from the input x based on training data {xi, yi} (orange points). For each input value x, the machine learning model predicts a distribution Pr(y|x) over the output y∈R (cyan curves show distributions for x=2.0 and x=7.0). Minimizing the loss function corresponds to maximizing the probability of the training outputs yi under the distribution predicted from the corresponding inputs xi. b) To predict discrete classes y∈{1, 2, 3, 4} in a classification task, we use a discrete probability distribution, so the model predicts a different histogram over the four possible values of yi for each value of xi. c) To predict counts y∈{0, 1, 2,...} and d) direction y∈(−π, π], we use distributions defined over positive integers and circular domains, respectively.
5.1.1 计算输出上的分布
5.1.1 Computing a distribution over outputs

This shift in perspective raises the question of exactly how a model f[ x , ϕ] can be adapted to compute a probability distribution. The solution is simple. First, we choose a parametric distribution Pr( y |θ) defined on the output domain y. Then we use the network to compute one or more of the parameters θ of this distribution.

For example, suppose the prediction domain is the set of real numbers, so y∈R. Here, we might choose the univariate normal distribution, which is defined on R. This distribution is defined by the mean µ and variance σ2, so θ={µ, σ2}. The machine learning model might predict the mean µ, and the variance σ2 could be treated as an unknown constant.

这种视角的转变提出了一个问题:究竟如何调整模型 f[ x ϕ] 以计算概率分布。解决方案很简单。首先,我们在输出域 y 上选择一个参数化分布 Pr (y |θ)。然后,我们使用网络计算该分布的一个或多个参数 θ。

例如,假设预测域为实数集,因此 y∈R。这里,我们可以选择定义在 R 上的一元正态分布。该分布由均值 µ 和方差 σ2 定义,因此 θ={µ, σ2}。机器学习模型可以预测均值 µ,而方差 σ2 可被视为未知常数。

5.1.2 最大似然准则
5.1.2 Maximum likelihood criterion

The model now computes different distribution parameters θi= f[ x i, ϕ] for each training input x i.

Each observed training output y i should have high probability under its corresponding distribution Pr( y i|θi). Hence, we choose the model parameters ϕ so that they maximize the combined probability across all I training examples: The combined probability term is the likelihood of the parameters, and hence equation 5.1 is known as the maximum likelihood criterion. 1 Here we are implicitly making two assumptions. First, we assume that the form of the probability distribution over the outputs y i is the same for each data point. Second, we assume that the conditional distributions Pr( y i| x i) of the output given the input are

模型现在为每个训练输入 x i 计算不同的分布参数 θi= f[ x i, ϕ]。每个观测到的训练输出 y i 都应在其对应的分布 Pr (y i|θi) 下具有较高的概率。因此,我们选择模型参数 ϕ,使它们最大化所有 I 个训练样本的联合概率:合并概率项是参数的似然,因此公式 5.1 被称为极大似然准则。 1这里我们隐含地做了两个假设。首先,我们假设输出 y i 上的概率分布的形式对每个数据点都相同。其次,我们假设给定输入时输出的条件分布 Pr( y i| x i) 是独立的,因此

independent, so the total likelihood of the training data decomposes as:

训练数据的总似然可以分解为:

图 5.2 对数变换。 a) 对数函数是单调递增的。如果 z > z′,则 log[z] > log[z′]。因此,任意函数 g[z] 的最大值将与
图 5.2 对数变换。 a) 对数函数是单调递增的。如果 z > z′,则 log[z] > log[z′]。因此,任意函数 g[z] 的最大值将与 log[ g[z]] 的最大值位于同一位置。 b) 一个函数 g[z]。 c) 该函数的对数 log[ g[z]]。 g[z] 上所有斜率为正的位置在对数变换后仍保持正斜率,斜率为负的位置仍保持负斜率。最大值的位置保持不变。Figure 5.2 The log transform. a) The log function is monotonically increasing. If z > z′, then log[z] > log[z′]. It follows that the maximum of any function g[z] will be at the same position as the maximum of log[ g[z]]. b) A function g[z]. c) The logarithm of this function log[ g[z]]. All positions on g[z] with a positive slope retain a positive slope after the log transform, and those with a negative slope retain a negative slope. The position of the maximum remains the same.
5.1.3 最大化对数似然
5.1.3 Maximizing log-likelihood

The maximum likelihood criterion (equation 5.1) is not very practical.

Each term Pr( y i| f[ x i, ϕ]) can be small, so the product of many of these terms can be tiny.

It may be difficult to represent this quantity with finite precision arithmetic. Fortunately, we can equivalently maximize the logarithm of the likelihood:

极大似然准则(公式 5.1)不太实用。每个项 Pr (y i| f[ x i, ϕ]) 都可能很小,因此许多这样的项的乘积可能极小。用有限精度算术表示这个量可能很困难。幸运的是,我们可以等价地最大化似然的对数:

This log-likelihood criterion is equivalent because the logarithm is a monotonically increasing function: if z > z′, then log[z] > log[z′] and vice versa (figure 5.2). It follows that when we change the model parameters ϕ to improve the log-likelihood criterion, we also improve the original maximum likelihood criterion. It also follows that the overall maxima of the two criteria must be in the same place, so the best model parameters ˆϕ are the same in both cases. However, the log-likelihood criterion has the practical advantage of using a sum of terms, not a product, so representing it with finite precision isn’t problematic.

这一对数似然准则是等价的,因为对数函数是单调递增函数:如果 z > z′,则 log [z] > log[z′],反之亦然(图 5.2)。由此可知,当我们改变模型参数 ϕ 以提高对数似然准则时,也会提高原来的极大似然准则。同样可知,两个准则的全局最大值必定位于同一位置,因此两种情况下的最佳模型参数 ϕ 相同。然而,对数似然准则具有实际优势:它使用各项之和而非乘积,因此用有限精度表示不会有问题。

5.1.4 最小化负对数似然
5.1.4 Minimizing negative log-likelihood

Finally, we note that, by convention, model fitting problems are framed in terms of minimizing a loss. To convert the maximum log-likelihood criterion to a minimization problem, we multiply by minus one, which gives us the negative log-likelihood criterion:

which is what forms the final loss function L[ϕ].

最后,我们注意到,按照惯例,模型拟合问题通常以最小化损失的形式表述。为了将最大对数似然准则转换为最小化问题,我们乘以负一,从而得到负对数似然准则:

这构成了最终的损失函数 L[ϕ]。

5.1.5 推断
5.1.5 Inference

The network no longer directly predicts the outputs y but instead determines a probability distribution over y. When we perform inference, we often want a point estimate rather than a distribution, so we return the maximum of the distribution:

It is usually possible to find an expression for this in terms of the distribution parameters θ predicted by the model. For example, in the univariate normal distribution, the maximum occurs at the mean µ.

网络不再直接预测输出 y,而是确定关于 y 的概率分布。当我们执行推断时,通常希望得到一个点估计而非分布,因此我们回报该分布的最大值:

通常可以根据模型预测的分布参数 θ 找到相应的表达式。例如,在一元正态分布中,最大值出现在均值 µ 处。

5.2 构造损失函数的方法
5.2 Recipe for constructing loss functions

The recipe for constructing loss functions for training data{ x i, y i} using the maximum likelihood approach is hence: 1. Choose a suitable probability distribution Pr( y |θ) defined over the domain of the

predictions y with distribution parameters θ. 2. Set the machine learning model f[ x , ϕ] to predict one or more of these parameters, 4. To perform inference for a new test example x, return either the full distribu-

因此,使用极大似然方法为训练数据 { x i, y i} 构造损失函数的方法如下:

1. 选择一个合适的概率分布 Pr (y |θ),其定义在预测值 y 的域上,分布参数为 θ。 2. 设置机器学习模型 f[ x ϕ] 来预测这些参数中的一个或多个,使得 θ= f[ x ϕ] 以及Pr (y |θ) = Pr (y | f[ x ϕ]) . ˆ 3. 为了训练模型,找到网络参数 ϕ,使其在训练数据集

tion Pr( y | f[ x ,ˆϕ]) or the value where this distribution is maximized.

We devote most of the rest of this chapter to constructing loss functions for common prediction types using this recipe.

对 { x i, y i} 上最小化负对数似然损失函数: 4. 要对新的测试样本 x 执行推断,请返回完整分布 ˆ Pr (y | f[ x ϕ]),或该分布取得最大值

时的值。我们将本章其余部分的大部分内容用于按照这一方法构建常见预测类型的损失函数。

图 5.3 一元正态分布(也称为高斯分布)定义在实数轴 z ∈ R 上,具有参数 µ 和 σ²。均值 µ 决定峰值的位置。方差 σ² 的正平方根(标准差)决定分
图 5.3 一元正态分布(也称为高斯分布)定义在实数轴 z ∈ R 上,具有参数 µ 和 σ²。均值 µ 决定峰值的位置。方差 σ² 的正平方根(标准差)决定分布的宽度。由于总概率密度之和为一,方差减小会使峰值变高,分布变窄。Figure 5.3 The univariate normal distribution (also known as the Gaussian distribution) is defined on the real line z ∈ R and has parameters µ and σ². The mean µ determines the position of the peak. The positive root of the variance σ² (the standard deviation) determines the width. Since the total probability density sums to one, the peak becomes higher as the variance decreases and the distribution becomes narrower.
5.3 示例 1:一元回归
5.3 Example 1: univariate regression

We start by considering univariate regression models. Here the goal is to predict a single scalar output y∈R from input x using a model f[ x , ϕ] with parameters ϕ. Following the recipe, we choose a probability distribution over the output domain y. We select the univariate normal distribution (figure 5.3), which is defined over y∈R. This has two parameters (mean µ and variance σ2) and has a probability density function:

Second, we set the machine learning model f[ x , ϕ] to compute one or more of the parameters of this distribution. Here, we just compute the mean so µ = f[ x , ϕ]:

我们首先考虑一元回归模型。这里的目标是使用参数为 ϕ 的模型 f[ x ϕ],从输入 x 预测单个标量输出 y∈R。按照这一方法,我们在输出域 y 上选择一个概率分布。我们选择一元正态分布(图 5.3),它定义在 y∈R 上。它有两个参数(均值 µ 和方差 σ2),并具有概率密度函数:

其次,我们设置机器学习模型 f[ x ϕ] 来计算该分布的一个或多个参数。这里我们只计算均值,因此 µ = f[ x ϕ]:

We aim to find the parameters ϕ that make the training data{ x i, yi} most probable under this distribution (figure 5.4). To accomplish this, we choose a loss function L[ϕ] based on the negative log-likelihood:

When we train the model, we seek parameters ˆϕ that minimize this loss.

我们旨在找到参数 ϕ,使训练数据 { x i, yi} 在该分布下的概率最大(图 5.4)。为此,我们选择基于负对数似然的损失函数 L[ϕ]:

ˆ 在训练模型时,我们寻找使该损失最小化的参数 ϕ。

5.3.1 最小二乘损失函数
5.3.1 Least squares loss function

Now let’s perform some algebraic manipulations on the loss function. We seek:

现在让我们对损失函数进行一些代数变换。我们寻求:

公式

where we removed the first term between the second and third lines because it doesn’t depend on ϕ. We removed the denominator between the third and fourth lines, as this is just a constant positive scaling factor that does not affect the position of the minimum.

The result of these manipulations is the least squares loss function that we originally introduced when we discussed linear regression in chapter 2: We see that the least squares loss function follows naturally from the assumptions that the predictions are (i) independent and (ii) drawn from a normal distribution with mean µ =

其中,我们在第二行和第三行之间去掉了第一项,因为它不依赖于 ϕ。我们在第三行和第四行之间去掉了分母,因为这只是一个正的常数缩放因子,不会影响最小值的位置。

这些操作的结果就是我们在第 2 章讨论线性回归时最初引入的最小二乘损失函数:我们可以看到,最小二乘损失函数自然源于以下假设,即

f[ x i, ϕ] (figure 5.4).

预测值 (i) 相互独立, (ii) 服从均值为 µ = f[ x i, ϕ] 的正态分布(图 5.4)。

5.3.2 推断
5.3.2 Inference

The network no longer directly predicts y but instead predicts the mean µ= f[ x , ϕ] of the normal distribution over y. When we perform inference, we usually want a single “best” point estimate ˆy, so we take the maximum of the predicted distribution:

For the univariate normal distribution, the maximum position is determined by the mean parameter µ (figure 5.3). This is precisely what the model computed, so ˆy= f[ x ,ˆϕ].

网络不再直接预测 y,而是预测正态分布的均值 µ= f[ x ϕ],该正态分布定义在 y 上。在进行推断时,我们通常希望得到一个“最佳”点估计 ˆ y,因此我们取预测分布的最大值:

对于单变量正态分布,最大值位置由均值 ˆ 参数 µ 决定(图 5.3)。这正是模型计算得到的结果,因此 ˆ y= f[ x ϕ]。

5.3.3 估计方差
5.3.3 Estimating variance

To formulate the least squares loss function, we assumed that the network predicted the mean of a normal distribution. The final expression in equation 5.11 (perhaps surpris-

为了构建最小二乘损失函数,我们假设网络预测了正态分布的均值。公式 5.11 中的最终表达式(也许令人惊讶 -

图 5.4 正态分布下最小二乘损失与极大似然损失的等价性。 a) 考虑图 2.2 中的线性模型。最小二乘准则最小化模型预测 f[xi, ϕ] (绿线)与真实输出
图 5.4 正态分布下最小二乘损失与极大似然损失的等价性。 a) 考虑图 2.2 中的线性模型。最小二乘准则最小化模型预测 f[xi, ϕ] (绿线)与真实输出值 yi (橙色点)之间偏差(虚线)的平方和。这里拟合良好,因此这些偏差较小(例如两个高亮点)。 b) 对于这些参数,拟合较差,平方偏差较大。 c) 最小二乘准则源自以下假设:模型预测输出的正态分布的均值,并且我们最大化概率。对于第一种情况,模型拟合良好,因此数据(水平橙色虚线)的概率 Pr (yi|xi) 较大(并且负对数概率较小)。 d) 对于第二种情况,模型拟合较差,因此概率较小,并且负对数概率较大。Figure 5.4 Equivalence of least squares and maximum likelihood loss for the normal distribution. a) Consider the linear model from figure 2.2. squares criterion minimizes the sum of the squares of the deviations (dashed lines) between the model prediction f[xi, ϕ] (green line) and the true output values yi (orange points). Here the fit is good, so these deviations are small (e.g., for the two highlighted points). b) For these parameters, the fit is bad, and the squared deviations are large. c) The least squares criterion follows from the assumption that the model predicts the mean of a normal distribution over the outputs and that we maximize the probability. For the first case, the model fits well, so the probability Pr(yi|xi) of the data (horizontal orange dashed lines) is large (and the negative log probability is small). d) For the second case, the model fits badly, so the probability is small and the negative log probability is large. The least

ingly) does not depend on the variance σ2. However, there is nothing to stop us from treating σ2 as a learned parameter and minimizing equation 5.9 with respect to both the model parameters ϕ and the distribution variance σ2:

In inference, the model predicts the mean µ = f[ x ,ˆϕ] from the input, and we learned the variance ˆσ2 during the training process. The former is the best prediction. The latter tells us about the uncertainty of the prediction.

(不出所料)不依赖于方差 σ2。然而,没有什么能阻止我们将 σ2 视为可学习参数,并同时针对模型参数 ϕ 和分布方差 σ2 最小化公式 5.9:

ˆ 在推理时,模型根据输入预测均值 µ = f[ x ϕ],而我们在训练过程中学习到了方差 ˆ σ2。前者是最佳预测,后者则描述了预测的不确定性。

5.3.4 异方差回归
5.3.4 Heteroscedastic regression

The model above assumes that the variance of the data is constant everywhere. However, this might be unrealistic. When the uncertainty of the model varies as a function of the input data, we refer to this as heteroscedastic (as opposed to homoscedastic, where the uncertainty is constant).

A simple way to model this is to train a neural network f[ x , ϕ] that computes both the mean and the variance. For example, consider a shallow network with two outputs. We denote the first output as f 1[ x , ϕ] and use this to predict the mean, and we denote the second output as f 2[ x , ϕ] and use it to predict the variance.

There is one complication; the variance must be positive, but we can’t guarantee that the network will always produce a positive output. To ensure that the computed variance is positive, we pass the second network output through a function that maps an arbitrary value to a positive one. A suitable choice is the squaring function, giving:

上述模型假设数据的方差处处恒定。然而,这可能并不现实。当模型的不确定性随输入数据变化时,我们称之为异方差的(与同方差的相反,后者的不确定性恒定)。

一种简单的建模方式是训练一个神经网络 f[ x ϕ],使其同时计算均值和方差。例如,考虑一个具有两个输出的浅层网络。我们将第一个输出记为 f 1[ x ϕ],并用它来预测均值;将第二个输出记为 f 2[ x ϕ],并用它来预测方差。

存在一个复杂之处;方差必须为正,但我们无法保证网络始终输出正值。为确保计算得到的方差为正,我们将网络的第二个输出输入到一个将任意值映射为正值的函数中。一个合适的选择是平方函数,得到:

Homoscedastic and heteroscedastic models are compared in figure 5.5.

由此得到损失函数:同方差和异方差模型的比较见图

5.5。

5.4 示例 2:二分类
5.4 Example 2: binary classification

In binaryclassification, the goal is to assign the data x to one of two discrete classes y∈ {0, 1}. In this context, we refer to y as a label. Examples of binary classification include (i) predicting whether a restaurant review is positive (y=1) or negative (y=0) from text data x and (ii) predicting whether a tumor is present (y=1) or absent (y=0) from an MRI scan x.

在二分类中,目标是将数据 x 分配给两个离散类别之一 y∈{0, 1}。在此语境下,我们将 y 称为标签。二分类的示例包括 (i) 从文本数据 x 预测餐厅评论是正面(y=1)还是负面(y=0),以及 (ii) 从 MRI 扫描 x 预测肿瘤是否存在(y=1)或不存在(y=0)。

图 5.5 同方差回归与异方差回归。 a) 用于同方差回归的浅层神经网络仅从输入 x 预测输出分布的均值 µ。 b) 结果是,虽然均值(蓝线)是输入 x 的分段
图 5.5 同方差回归与异方差回归。 a) 用于同方差回归的浅层神经网络仅从输入 x 预测输出分布的均值 µ。 b) 结果是,虽然均值(蓝线)是输入 x 的分段线性函数,但方差处处恒定(箭头和灰色区域显示 ±2 标准差)。 c) 用于异方差回归的浅层神经网络还预测方差 σ2 (或更准确地说,先计算其平方根,然后再平方)。 d) 标准差现在也变成输入 x 的分段线性函数。Figure 5.5 Homoscedastic vs. heteroscedastic regression. network for homoscedastic regression predicts just the mean µ of the output distribution from the input x. b) The result is that while the mean (blue line) is a piecewise linear function of the input x, the variance is constant everywhere (arrows and gray region show ±2 standard deviations). network for heteroscedastic regression also predicts the variance σ2 (or, more precisely, computes its square root, which we then square). deviation now also becomes a piecewise linear function of the input x. a) A shallow neural c) A shallow neural d) The standard

Once again, we follow the recipe from section 5.2 to construct the loss function. First, we choose a probability distribution over the output space y∈{0, 1}. A suitable choice is the Bernoulli distribution, which is defined on the domain{0, 1}. This has a single parameter λ ∈[0, 1] that represents the probability that y takes the value one (figure 5.6):

同样,我们遵循第 5.2 节的方法构建损失函数。首先,我们在输出空间 y∈{0, 1} 上选择一个概率分布。合适的选择是伯努利分布,其定义域为 {0, 1}。它只有一个参数 λ ∈[0, 1],表示 y 取值为 1 的概率(图 5.6):

图 5.6 伯努利分布。伯努利分布定义在域 z ∈ {0, 1} 上,只有一个参数 λ,表示观测到 z = 1 的概率。因此,观测到 z = 0 的概率为 1
图 5.6 伯努利分布。伯努利分布定义在域 z ∈ {0, 1} 上,只有一个参数 λ,表示观测到 z = 1 的概率。因此,观测到 z = 0 的概率为 1 − λ。Figure 5.6 Bernoulli distribution. The Bernoulli distribution is defined on the domain z ∈ {0, 1} and has a single parameter λ that denotes the probability of observing z = 1. It follows that the probability of observing z = 0 is 1 − λ.
图 5.7 logistic sigmoid 函数。该函数将实数轴 z∈R 映射到 0 和 1 之间的数,因此 sig[z] ∈[0, 1]。输入 0 映射到
图 5.7 logistic sigmoid 函数。该函数将实数轴 z∈R 映射到 0 和 1 之间的数,因此 sig[z] ∈[0, 1]。输入 0 映射到 0.5。负输入映射到小于 0.5 的数,正输入映射到大于 0.5 的数。分布。这表示 y=1 的概率,由此可知 1−λ 表示 y= 0 的概率。在进行推断时,我们可能想要一个点对 y 的估计值,因此当 λ > 0.5 时我们设置 y= 1,否则设置 y= 0。Figure 5.7 This function maps the real line z∈ R to numbers between zero and one, so sig[z] ∈[0, 1]. An input of 0 is mapped to 0.5. Negative inputs are mapped to numbers below 0.5, and positive inputs to numbers above 0.5.

which can equivalently be written as:

Second, we set the machine learning model f[ x , ϕ] to predict the single distribution parameter λ. However, λ can only take values in the range [0, 1], and we cannot guarantee that the network output will lie in this range. Consequently, we pass the network output through a function that maps the real numbers R to[0, 1]. A suitable function is the logistic sigmoid (figure 5.7):

这也可以等价地写为:

其次,我们设置机器学习模型 f[ x ϕ] 来预测单个分布参数 λ。然而, λ 只能取值于范围 [0, 1],,且我们无法保证网络输出落在该范围内。因此,我们将网络输出通过一个将实数 R 映射到 [0, 1] 的函数。合适的函数是 logisticsigmoid (图 5.7):

This is depicted in figure 5.8 for a shallow neural network model. The loss function is the negative log-likelihood of the training set:

图 5.8 展示了浅层神经网络模型中的这一过程。损失函数是训练集的负对数似然:

For reasons to be explained in section 5.7, this is known as the binary cross-entropy loss. The transformed model output sig[ f[ x , ϕ]] predicts the parameter λ of the Bernoulli

由于将在第 5.7 节中解释的原因,这被称为二元交叉熵损失。变换后的模型输出 sig[ f[ x ϕ]] 预测伯努利分布的参数 λ

distribution. This represents the probability that y=1, and it follows that 1−λ represents the probability that y= 0. When we perform inference, we may want a point

estimate of y, so we set y= 1 if λ > 0.5 and y= 0 otherwise.

图 5.8 二分类模型。 a) 网络输出是一个分段线性函数,可以取任意实数值。 b) 该输出经过 logistic sigmoid 函数转换,将这些值压缩到范围
图 5.8 二分类模型。 a) 网络输出是一个分段线性函数,可以取任意实数值。 b) 该输出经过 logistic sigmoid 函数转换,将这些值压缩到范围 [0, 1]。 c) 转换后的输出预测概率 λ,即 y=1 (实线)。因此 y=0 的概率为 1 −λ (虚线)。对于任意固定的 x (垂直切片),我们得到类似于图 5.6 的伯努利分布的两个值。损失函数偏好能够产生较大 λ 值的模型参数,这些值位于位置 xi,且这些位置与正例 yi=1 相关联;并在相应位置产生较小的 λ 值,这些位置与负例 yi= 0 相关联。Figure 5.8 Binary classification model. linear function that can take arbitrary real values. b) This is transformed by the logistic sigmoid function, which compresses these values to the range[0, 1]. c) The transformed output predicts the probability λ that y=1 (solid line). The probability that y=0 is hence 1 −λ (dashed line). For any fixed x (vertical slice), we retrieve the two values of a Bernoulli distribution similar to that in figure 5.6. The loss function favors model parameters that produce large values of λ at positions xi that are associated with positive examples yi=1 and small values of λ at positions associated with negative examples yi= 0.
图 5.9 类别分布。类别分布为 K > 2 个类别分配概率,相应概率为 λ1,λ2,…,λK。这里共有五个类别,因此 K = 5。为确保这是一个有效的概率分布
图 5.9 类别分布。类别分布为 K > 2 个类别分配概率,相应概率为 λ1,λ2,…,λK。这里共有五个类别,因此 K = 5。为确保这是一个有效的概率分布,每个参数 λk 必须位于 [0, 1] 内,且所有 K 个参数之和必须为 1。Figure 5.9 Categorical distribution. The categorical distribution assigns probabilities to K > 2 categories, with associated probabilities λ1, λ2, …, λK. Here there are five categories, so K = 5. To ensure a valid probability distribution, each parameter λk must lie in [0, 1], and all K parameters must sum to one.
5.5 示例 3:多分类
5.5 Example 3: multiclass classification

The goal of multiclassclassification is to assign an input data example x to one of K> 2 classes, so y∈{1, 2,..., K}. Real-world examples include (i) predicting which of K= 10 digits y is present in an image x of a handwritten number and (ii) predicting which of K possible words y follows an incomplete sentence x.

We once more follow the recipe from section 5.2.

We first choose a distribution over the prediction space y.

多分类的目标是将输入数据示例 x 归入 K> 2 个类别之一,因此 y∈{1, 2,..., K}。现实世界中的示例包括 (i) 预测 K= 10 个数字中 y 出现在手写数字图像 x 中,以及 (ii) 预测 K 个可能词中 y 跟在未完成句子 x 之后。

In this case, we have y∈{1, 2,..., K}, so we choose the categoricaldistribution (figure 5.9), which is defined on this domain. This has K parameters λ1, λ2,..., λK, which determine the probability of each category:

我们再次遵循第 5.2 节的方法。我们首先在预测空间 y 上选择一个分布。在这种情况下,我们有 y∈{1, 2,..., K},因此选择类别分布(图 5.9),它在该定义域上定义。它具有 K 个参数 λ1, λ2,..., λK,它们决定每个类别的概率:

The parameters are constrained to take values between zero and one, and they must collectively sum to one to ensure a valid probability distribution.

Then we use a network f[ x , ϕ] with K outputs to compute these K parameters from the input x. Unfortunately, the network outputs will not necessarily obey the aforementioned constraints. Consequently, we pass the K outputs of the network through a function that ensures these constraints are respected. A suitable choice is the softmax function (figure 5.10). This takes an arbitrary vector of length K and returns a vector of the same length but where the elements are now in the range[0, 1] and sum to one. The kth output of the softmax function is: softmax k[ z ] = where the exponential functions ensure positivity, and the sum in the denominator en-

参数的取值被约束在 0 到 1 之间,并且它们的总和必须为 1,以确保得到有效的概率分布。

然后,我们使用网络 f[ x ϕ],它具有 K 个输出,用于从输入 x 计算这些 K 个参数。遗憾的是,网络输出不一定满足前述约束。因此,我们将网络的 K 个输出输入到一个确保这些约束得到满足的函数中。一个合适的选择是 Softmax 函数(图 5.10)。它接受一个长度为 K 的任意向量,并返回一个长度相同的向量,其中各元素现在位于范围 [0, 1] 内且总和为 1。 Softmax 函数的第 kth 个输出为: softmax k[ z ] =其中指数函数确保为正,并且分母中的和

sures that the K numbers sum to one.

确保这些 K 个数值之和为一。

The likelihood that input x has label y= k (figure 5.10) is hence:

The loss function is the negative log-likelihood of the training data:

输入 x 具有标签 y= k (图 5.10)的似然因此为:

损失函数是训练数据的负对数似然:

For reasons that will be explained in section 5.7, this is known as the multiclass crossentropy loss. The transformed model output represents a categorical distribution over possible classes y∈{1, 2,..., K}. For a point estimate, we take the most probable category ˆy=

i 和 k′th 输出。由于将在第 5.7 节解释的原其中 f yi[ x ϕ] 和 f k′[ x ϕ] 分别表示网络的 yth 因,这被称为多类交叉熵损失。转换后的模型输出表示一个关于可能的类别分布

图 5.10 针对 K =3 个类别的多分类。 a) 网络具有三个分段线性输出,可取任意值。 b) 在 Softmax 函数之后,这些输出被约束为非负且总和为
图 5.10 针对 K =3 个类别的多分类。 a) 网络具有三个分段线性输出,可取任意值。 b) 在 Softmax 函数之后,这些输出被约束为非负且总和为 1。因此,对于给定输入 x,我们计算类别分布的有效参数:该图的任意垂直切片都会产生三个总和为 1 的值,这些值会构成类似于图 5.9 的类别分布中条形的高度。Figure 5.10 Multiclass classification for K =3 classes. a) The network has three piecewise linear outputs, which can take arbitrary values. b) After the softmax function, these outputs are constrained to be non-negative and sum to one. Hence, for a given input x, we compute valid parameters for the categorical distribution: any vertical slice of this plot produces three values that sum to one and would form the heights of the bars in a categorical distribution similar to figure 5.9.

value of x in figure 5.10.

5.5.1 预测其他数据类型
5.5.1 Predicting other data types

In this chapter, we have focused on regression and classification because these problems are widespread. However, to make different types of predictions, we simply choose an appropriate distribution over that domain and apply the recipe in section 5.2. Figure 5.11 enumerates a series of probability distributions and their prediction domains. Some of these are explored in the problems at the end of the chapter.

在本章中,我们重点介绍了回归和分类,因为这些问题非常普遍。然而,为了做出不同类型的预测,我们只需在该领域上选择适当的分布,并应用 5.2 节中的方法。图 5.11 列举了一系列概率分布及其预测领域。其中一些

这些内容在章末习题中探讨。

5.6 多个输出
5.6 Multiple outputs

Often, we wish to make more than one prediction with the same model, so the target output y is a vector.

For example, we might want to predict a molecule’s melting and boiling point (a multivariate regression problem, figure 1.2b) or the object class at every point in an image (a multivariate classification problem, figure 1.4a). While it is possible to define multivariate probability distributions and use a neural network to model their parameters as a function of the input, it is more usual to treat each prediction as independent. Independence implies that we treat the probability Pr( y | f[ x , ϕ]) as a product of

通常,我们希望使用同一个模型进行多次预测,因此目标输出 y 是一个向量。例如,我们可能想要预测分子的熔点和沸点(多元回归问题,图 1.2b)或图像中每个点的对象类别(多元分类问题,图 1.4a)。虽然可以定义多元概率分布,并使用神经网络将其参数建模为输入的函数,但更常见的是将每个预测视为独立的。独立性意味着我们将概率 Pr( y | f[ x ϕ]) 视为乘积

univariate terms for each element yd∈ y: where f d[ x , ϕ] is the dth set of network outputs, which describe the parameters of the distribution over yd. For example, to predict multiple continuous variables yd∈R, we use a normal distribution for each yd, and the network outputs f d[ x , ϕ] predict the means of these distributions. To predict multiple discrete variables yd∈{1, 2,..., K}, we use a

每个元素 yd∈ y 的单变量项:其中 f d[ x ϕ] 是 dth 一组网络输出,它们描述 yd 上的分布的参数。例如,要预测多个连续变量 yd∈R,我们对每个 yd 使用正态分布,网络输出 f d[ x ϕ] 预测这些分布的均值。要预测多个离散变量 yd∈{1, 2,..., K},我们使用一个

公式
图 5.11 不同预测类型损失函数的分布。
图 5.11 不同预测类型损失函数的分布。Figure 5.11 Distributions for loss functions for different prediction types.

categorical distribution for each yd. Here, each set of network outputs f d[ x , ϕ] predicts the K values that contribute to the categorical distribution for yd.

When we minimize the negative log probability, this product becomes a sum of terms:

类别分布,每个 yd 一个。在这里,每组网络输出 f d[ x ϕ] 预测 K 值,这些值用于 yd 的类别分布。

当我们最小化负对数概率时,该乘积变为各项之和:

where yid is the dth output from the ith training example. To make two or more prediction types simultaneously, we similarly assume the errors in each are independent. For example, to predict wind direction and strength, we might

其中 yid 是来自 ith 训练样本的 dth 输出。

choose the von Mises distribution (defined on circular domains) for the direction and the exponential distribution (defined on positive real numbers) for the strength. The independence assumption implies that the joint likelihood of the two predictions is the product of individual likelihoods. These terms will become additive when we compute the negative log-likelihood.

对于方向选择冯 · 米塞斯分布(定义在圆形域上),对于强度选择指数分布(定义在正实数上)。独立性假设意味着两个预测的联合似然是各自似然的乘积。当我们计算负对数似然时,这些项会变为相加。

图 5.12 交叉熵方法。 a) 训练样本的经验分布(箭头表示狄拉克 δ 函数)。 b) 模型分布(参数为 θ={µ, σ2} 的正态分布)。在交叉熵方法中,我
图 5.12 交叉熵方法。 a) 训练样本的经验分布(箭头表示狄拉克 δ 函数)。 b) 模型分布(参数为 θ={µ, σ2} 的正态分布)。在交叉熵方法中,我们将这两个分布之间的距离(KL 散度)作为模型参数 θ 的函数进行最小化。Figure 5.12 Cross-entropy method. a) Empirical distribution of training samples (arrows denote Dirac delta functions). b) Model distribution (a normal distribution with parameters θ={µ, σ2}). In the cross-entropy approach, we minimize the distance (KL divergence) between these two distributions as a function of the model parameters θ.
5.7 交叉熵损失
5.7 Cross-entropy loss

In this chapter, we developed loss functions that minimize negative log-likelihood. However, the term cross-entropy loss is also commonplace. In this section, we describe the cross-entropy loss and show that it is equivalent to using negative log-likelihood.

The cross-entropy loss is based on the idea of finding parameters θ that minimize the distance between the empirical distribution q(y) of the observed data y and a model distribution Pr(y|θ) (figure 5.12). The distance between two probability distributions q(z) and p(z) can be evaluated using the Kullback-Leibler (KL) divergence: Now consider that we observe an empirical data distribution at points{yi}I

在本章中,我们开发了最小化负对数似然的损失函数。然而,交叉熵损失这一术语也很常见。在本节中,我们描述交叉熵损失,并说明它等同于使用负对数似然。交叉熵损失基于这样的思想:寻找参数 θ,使观测数据 y 的经验分布 q (y) 与模型分布 Pr (y|θ) 之间的距离最小化(图 5.12)。两个概率分布 q (z) 之间的距离

与 p(z) 可以使用 Kullback-Leibler (KL) 散度计算:现在考虑我们在点{yi}I

can describe this as a weighted sum of point masses:

i=1 处观测到一个经验数据分布。我们可以将其描述为点质量的加权和:

where δ[•] is the Dirac delta function. We want to minimize the KL divergence between the model distribution Pr(y|θ) and this empirical distribution:

其中 δ[•] 是狄拉克 δ 函数。我们希望最小化 KL 散度,二者之间模型分布 Pr(y|θ) 和这个经验分布:

公式

where the first term disappears, as it has no dependence on θ. The remaining second term is known as the cross-entropy. It can be interpreted as the amount of uncertainty that remains in one distribution after taking into account what we already know from the other. Now, we substitute in the definition of q(y) from equation 5.28:

其中第一项消失,因为它不依赖于 θ。剩下的第二项被称为交叉熵。它可以解释为:在考虑了从另一个分布中已经获得的信息之后,一个分布中仍然保留的不确定性。现在,我们将式 5.28 中 q (y) 的定义代入:

The product of the two terms in the first line corresponds to pointwise multiplying the point masses in figure 5.12a with the logarithm of the distribution in figure 5.12b. We are left with a finite set of weighted probability masses centered on the data points. In the last line, we have eliminated the constant scaling factor 1/I, as this does not affect the position of the minimum.

In machine learning, the distribution parameters θ are computed by the model f[ x i, ϕ], so we have:

第一行中两项的乘积,对应于将图 5.12a 中的点质量与图 5.12b 中分布的对数进行逐点相乘。我们最终得到的是有限的一组以数据点为中心的带权重概率质量。在最后一行中,我们消去了常数缩放因子 1/I,因为它不会影响最小值的位置。

在机器学习中,分布参数 θ 由模型 f[ x i, ϕ] 计算得到,因此我们有:

This is precisely the negative log-likelihood criterion from the recipe in section 5.2.

It follows that the negative log-likelihood criterion (from maximizing the data likelihood) and the cross-entropy criterion (from minimizing the distance between the model and empirical data distributions) are equivalent.

这正是第 5.2 节方法中的负对数似然准则。

由此可知,负对数似然准则(来自最大化数据似然)与交叉熵准则(来自最小化模型分布与经验数据分布之间的距离)是等价的。

5.8 小结
5.8 Summary

We previously considered neural networks as directly predicting outputs y from data x. In this chapter, we shifted perspective to think about neural networks as computing the parameters θ of probability distributions Pr( y |θ) over the output space. This led to a principled approach to building loss functions. We selected model parameters ϕ that maximized the likelihood of the observed data under these distributions. We saw that this is equivalent to minimizing the negative log-likelihood. The least squares criterion for regression is a natural consequence of this approach; it follows from the assumption that y is normally distributed and that we are predicting the mean. We also saw how the regression model could be (i) extended to estimate the uncertainty over the prediction and (ii) extended to make that uncertainty dependent on the input (the heteroscedastic model). We applied the same approach to both binary and multiclass classification and derived loss functions for each. We discussed how to

tackle more complex data types and how to deal with multiple outputs. Finally, we argued that cross-entropy is an equivalent way to think about fitting models.

In previous chapters, we developed neural network models. In this chapter, we developed loss functions for deciding how well a model describes the training data for a given set of parameters. The next chapter considers model training, in which we aim to find the model parameters that minimize this loss.

我们此前将神经网络视为直接从数据 x 预测输出 y。在本章中,我们转变了视角,将神经网络视为计算输出空间上概率分布的参数 θPr (y |θ)。这促成了一种构建损失函数的原则性方法。我们选择了模型参数 ϕ,使其在这些分布下最大化观测数据的似然。我们发现这等价于最小化负对数似然。回归的最小二乘准则是这一方法的自然结果;它源于假设 y 服从正态分布,并且我们预测的是均值。我们还看到了回归模型如何 (i) 扩展以估计预测的不确定性,以及 (ii) 扩展以使该不确定性依赖于输入(异方差模型)。我们将相同的方法应用于二分类和多分类,并为各自推导了损失函数。我们讨论了如何

在前面的章节中,我们构建了神经网络模型。在本章中,我们推导了损失函数,用于判断在给定的一组参数下模型对训练数据的拟合程度。下一章将讨论模型训练,其目标是找到使该损失最小化的模型参数。

注释
Notes

Losses based on the normal distribution:

Robust regression:

基于正态分布的损失: Nix 与 Weigend (1994)以及 Williams (1996)研究了异方差非线性

Estimating quantiles:

Class imbalance and focal loss:

Learning to rank:

Other data types:

图 5.13 von Mises 分布定义在圆形定义域(−π, π])上。它有两个参数。均值 µ 决定峰值的位置。集中参数 κ> 0 的作用类似于方差的倒
图 5.13 von Mises 分布定义在圆形定义域(−π, π])上。它有两个参数。均值 µ 决定峰值的位置。集中参数 κ> 0 的作用类似于方差的倒数。因此 1/√κ 大致相当于正态分布中的标准差。(见图 5.14),以输入为条件。 Prokudin 等(2018)使用 von Mises 分布预测方向(见图 5.13)。 Fallah 等(2009)使用泊松分布为计数预测构建了损失函数(见图 5.15)。 Ng 等(2017)使用基于伽马分布的损失函数来预测持续时间。Figure 5.13 The von Mises distribution is defined over the circular domain(−π, π]. It has two parameters. The mean µ determines the position of the peak. The concentration κ> 0 acts like the inverse of the variance. Hence 1/√κ is roughly equivalent to the standard deviation in a normal distribution. (see figure 5.14) that is conditional on the input. Prokudin et al. (2018) used the von Mises distribution to predict direction (see figure 5.13). Fallah et al. (2009) constructed loss functions for prediction counts using the Poisson distribution (see figure 5.15). Ng et al. (2017) used loss functions based on the gamma distribution to predict duration.

Non-probabilistic approaches:

习题
Problems
图 5.14 多峰数据与高斯混合密度。 a) 示例训练数据,其中对于输入 x 的中间值,对应的输出 y 遵循两条路径之一。例如,在 x=0 处,输出 y 可能大
图 5.14 多峰数据与高斯混合密度。 a) 示例训练数据,其中对于输入 x 的中间值,对应的输出 y 遵循两条路径之一。例如,在 x=0 处,输出 y 可能大致为 −2 或 +3,但不太可能介于这两个值之间。 b) 高斯混合是一种适合这种数据的概率模型。顾名思义,该模型是两个或更多具有不同均值和方差的正态分布的加权和(实心青色曲线)(此处为两个正态分布,虚线蓝色和橙色曲线)。当均值相距较远时,这会形成多峰分布。 c) 当均值接近时,混合模型可以建模单峰但非正态的密度。其中 µ 是平均方向的度量, κ 是集中度的度量(即方差的倒数)。 Bessel 0[κ] 是零阶第一类修正贝塞尔函数。使用第 5.2 节中的方法,为学习模型 f[ x ϕ] 的参数 µ 制定损失函数,以预测最可能的风向。你的解法应将集中度 κ 视为常数。你会如何进行推断? 问题 5. 4 ∗ 有时,输入 x 对应的输出 y 是多峰的(图 5.14a);对于给定输入,存在不止一个有效预测。此处,我们可以使用正态分布分量的加权和作为输出的分布。这称为高斯混合模型。例该模型可以表示具有两个峰的分布(图 5.14b)或具有一个峰但形状更复杂的分布(图 5.14c)。使用 5.2 节的方法构造一个损失函数,用于训练模型 f[x, ϕ],该模型接收输入 x、具有参数 ϕ,并预测两个高斯分布的混合。损失应基于 I 个训练数据对{xi, yi}。在执行推理时,你预见会出现哪些问题? 问题 5.5 考虑将问题 5.3 中的模型扩展为使用两个冯 · 米塞斯分布的混合来预测风向。写出该模型的似然表达式 Pr(y|θ)。网络需要产生多少个输出?Figure 5.14 Multimodal data and mixture of Gaussians density. training data where, for intermediate values of the input x, the corresponding output y follows one of two paths. For example, at x=0, the output y might be roughly −2 or +3 but is unlikely to be between these values. b) The mixture of Gaussians is a probability model suited to this kind of data. As the name suggests, the model is a weighted sum (solid cyan curve) of two or more normal distributions with different means and variances (here, two normal distributions, dashed blue and orange curves). When the means are far apart, this forms a multimodal distribution. c) When the means are close, the mixture can model unimodal but non-normal densities. where µ is a measure of the mean direction and κ is a measure of concentration (i.e., the inverse of the variance). The term Bessel 0[κ] is a modified Bessel function of the first kind of order 0. Use the recipe from section 5.2 to develop a loss function for learning the parameter µ of a model f[ x , ϕ] to predict the most likely wind direction. Your solution should treat the concentration κ as constant. How would you perform inference? Problem 5.4 ∗ Sometimes, the outputs y for input x are multimodal (figure 5.14a); there is more than one valid prediction for a given input. Here, we might use a weighted sum of normal components as the distribution over the output. This is known as a mixture of Gaussians model. (figure 5.14b) or a distribution with one peak but a more complex shape (figure 5.14c). Use the recipe from section 5.2 to construct a loss function for training a model f[x, ϕ] that takes input x, has parameters ϕ, and predicts a mixture of two Gaussians. The loss should be based on I training data pairs{xi, yi}. What problems do you foresee when performing inference? Problem 5.5 Consider extending the model from problem 5.3 to predict the wind direction using a mixture of two von Mises distributions. Write an expression for the likelihood Pr(y|θ) for this model. How many outputs will the network need to produce? a) Example
图 5.15 泊松分布。该离散分布定义在非负整数 z∈{0, 1, 2,...} 上。它只有一个参数 λ∈R+,称为率,也是分布的均值。 a–c) 率分别为 1
图 5.15 泊松分布。该离散分布定义在非负整数 z∈{0, 1, 2,...} 上。它只有一个参数 λ∈R+,称为率,也是分布的均值。 a–c) 率分别为 1.4、 2.8 和 6.0 的泊松分布。问题 5.6 考虑构建一个模型,预测未来一分钟内经过城市中某个给定点的行人数量 y∈{0, 1, 2,...},该模型基于数据 x,其中包含一天中的时间、经度和纬度以及社区类型等信息。适合对计数进行建模的分布是泊松分布(图 5.15)。它只有一个参数 λ>0,称为率,表示该分布的均值。该分布的概率密度函数为:假设我们可以获得 I 个训练对 { x i, yi},请为该模型设计一个损失函数。问题 5.7 考虑一个多元回归问题,其中我们预测十个输出,因此 y ∈R10,并用独立的正态分布对每个输出进行建模,其中均值 µd 由网络预测,方差 σ2 为常数。写出似然函数 Pr (y | f[ x ϕ]) 的表达式。证明在不估计方差 σ2 的情况下,最小化该模型的负对数似然仍然等价于最小化平方项之和。问题 5。 8 ∗ 构造一个损失函数,用于进行多元预测 y 差 σ2 d 的独立正态分布。假设一个异方差模型,使得均值 µd 和方差 σ2 化。问题 5。 9 ∗ 考虑一个多元回归问题,其中我们根据数据 x 预测一个人的身高(以米为单位)及其权重(以公斤为单位)。这里,单位所对应的取值范围差异很大。你认为这会导致哪些问题?请针对这些问题提出两个解决方案。问题 5.10 扩展问题 5.3 中的模型,以同时预测风向和风速,并定义相应的损失函数。Figure 5.15 Poisson distribution. This discrete distribution is defined over nonnegative integers z∈{0, 1, 2,...}. It has a single parameter λ∈R+, which is known as the rate and is the mean of the distribution. a–c) Poisson distributions with rates of 1.4, 2.8, and 6.0, respectively. Problem 5.6 Consider building a model to predict the number of pedestrians y∈{0, 1, 2,...} that will pass a given point in the city in the next minute, based on data x that contains information about the time of day, the longitude and latitude, and the type of neighborhood. A suitable distribution for modeling counts is the Poisson distribution (figure 5.15). This has a single parameter λ>0 called the rate that represents the mean of the distribution. The distribution has probability density function: Design a loss function for this model assuming we have access to I training pairs{ x i, yi}. Problem 5.7 Consider a multivariate regression problem where we predict ten outputs, so y ∈ R10, and model each with an independent normal distribution where the means µd are predicted by the network, and variances σ2 are constant. Show that minimizing the negative log-likelihood of this model is still equivalent to minimizing a sum of squared terms if we don’t estimate the variance σ2. Problem 5.8 ∗ Construct a loss function for making multivariate predictions y ∈RDo based on independent normal distributions with different variances σ2 a heteroscedastic model so that both the means µd and variances σ2 data. Problem 5.9 ∗ Consider a multivariate regression problem in which we predict the height of a person in meters and their weight in kilos from data x. Here, the units take quite different ranges. What problems do you see this causing? Propose two solutions to these problems. Problem 5.10 Extend the model from problem 5.3 to predict both the wind direction and the wind speed and define the associated loss function.
公式