PRML Notes - 3.1 Linear Basis Function Model

Chilly_Rain posted @ 2012年1月31日 22:43 in Pattern Recognition and Maching Learning with tags 基函数 线性回归模型 , 3147 阅读

书中第三章的标题是Linear Model for Regression,即线性回归模型。线性模型的定义是相对于“未知参数”的线性函数。也就是说,虽然下面这个模型可以称为线性模型(实际上是最简单的线性模型,因为它不仅相对于未知参数是线性的,而且相对于输入变量也是线性的),但是其实际的定义要宽泛得多,因而才有了本节介绍的“线性基函数”模型。

$$y(x, w) = w_0 + w_1x_1 + \ldots + w_Dx_D$$

回归问题

给定训练数据集$(\textbf {x}_i, t_i)$, $i = 1 \ldots N$,其中$\textbf {x}_i$为D维变量,$t_i$为响应值。

最简单的方法,我们希望通过数据得到一个响应值估计函数$y(\textbf{x})$,从而可以对未来的输入变量进行响应值预测。从概率的观点来看,我们要得到的不仅是一个输入变量的单点估计值,而是一个条件分布$p(t|\textbf{x})$,从而可以表达其响应值的不确定性。得到这个分布,实际我们就完成了“推演”的工作,“决策”步骤中,我们需要定义一个误差函数(比如第一章中提到的平方误差),再以最小化期望误差为目的来决策每个输入变量的响应值(在平方误差下,这个“决策”是响应值t的条件期望值)。

基函数(basis function)

相比于最开始提到的那个“最简单”的线性模型,更一般的线性模型可以表达为

$$y(\textbf{x}, \textbf{w}) = w_0 + \sum_{j=1}^{M-1} w_j\phi(\textbf{x}) = \sum_{j=1}^{M} w_j\phi(\textbf{x}) = \mathbf{w}^{T}\mathbf{\phi}(\mathbf x)$$

其中所有的$\phi_j(\textbf{x})$都称为基函数。特别地,$\phi_0(\mathbf{x}) = 1$以容许$w_0$对函数的值产生一定的偏移(bias)。基函数的作用可以表现的预处理(如特征抽取)上,如PCA,MDS等经典的特征抽取算法都是以原坐标为基础进行线性组合,形成新坐标,再把数据表示的新的坐标下,以图可以更好地发现数据中的规律(例如PCA是把数据中方差最大的方向作为新的坐标体系)。而数据在新坐标体系下的坐标值就可以用这M个基函数来表示。

虽然是作用于线性模型中,基函数并不必须是线性函数,从而极大地扩充了最简单线性模型的表达能力。多项式模型就是非线性基函数的一个实例。

spline function:非输入变量的全局函数,因此可以把输入空间划分成独立的部分,一部分的变化不会影响其它部分(不懂,待研究)

除多项式基函数外,其它一些基函数的例子包括

  • Gaussian基函数:$$\phi_j(x) = exp(-\frac{(x-\mu_j)^2}{2s^2})$$
  • sigmoidal基函数:$$\phi_j(x) = \sigma(\frac{x-\mu_j}{s})$$,其中$$\sigma(a) = \frac{1}{1+exp(-a)}$$
  • tanh基函数:$$tanh(a)=2\sigma(a)-1$$,因此sigmoidal基函数的线性组合也是tanh基函数的线性组合
  • Fourier基函数:晕

极大似然法和最小二乘法

假设响应值t是由一个以x为输入的确定的函数加上一个高斯噪声而得到的,即

$$t = y(\mathbf{x}, \mathbf{w}) + \epsilon$$

其中$\epsilon$是符合正态分布$N(0, \beta^{-1})$的噪声变量。那么我们希望得到的条件分布可以写作

$$P(t|\mathbf{x}, \mathbf{w}, \beta) = N(t|y(\mathbf{x}, \mathbf{w}), \beta^{-1})$$

如果假设我们在决策时所选的误差函数就是平方误差,那么决策函数就是以上分布的条件期望,即$y(\mathbf{x}, \mathbf{w})$

这里需要注意的一点是,高期噪声假设在多峰值的场景下是不适合的。

假设给定的N个数据是独立同分布的(iid),那么对数似数函数可写作

$$lnP(\mathbf{t}|\mathbf{x}, \mathbf{w}, \beta) = \sum_{i=1}^{N}lnN(t_i|\mathbf{w}^T\phi(\mathbf{x_i}), \beta^{-1}) = \frac{N}{2}ln\beta - \frac{N}{2}ln(2\pi) - \beta E_D(\mathbf{w})$$

其中$E_D(\mathbf{w})$为Sum-of-square误差函数(请参见第一章)。当我们使用求导的方法来计算参数$\mathbf{w}$时会发现,正如第一章所述,由于表达的前两项没包含$\mathbf{w}$,因此对ML和LS求导实际是等价的。

$$\mathbf{w}_{ML} = (\Phi^T\Phi)^{-1}\Phi \mathbf{t}$$

这个等式称为最小二乘问题的正规式(normal equations)。而$\Phi$是一个N*M阶的矩阵,其中$\Phi_{ij} = \phi_j(x_i)$。 等号右侧除t之外的部分称为矩阵$\Phi$的伪逆矩阵,可以看作是非方阵的逆阵。特别地,当$\Phi$是方阵时,伪逆阵等于逆阵。

下面对$w_0$的意义做深入探索。对$E_D(\mathbf{w})$稍作变形,可得

$$E_{D}(\mathbf{w}) = \frac{1}{2}\sum_{i=1}^{N}(t_i - w_0 - \sum_{j=1}^{M-1}w_j\phi_j(x_i))^2$$

再对$w_0$对导数,可解得

$$w_0 = \bar t - \sum_{j=1}^{M-1}w_j\bar{\phi_j}$$,其中$$\bar t = \frac{1}{N}\sum_{i=1}^{N}t_i$$$$\bar \phi_j = \frac{1}{N}\sum_{i=1}^{N}\phi_j(x_i)$$

因此$w_0$可以解释为训练集中平均响应值,与训练集平均基函数值的加权平均之间的差。

同样地,对极大似数函数相对于$\beta$进行求导,可得参数值为

$$\frac{1}{\beta} = \frac{1}{N}\sum_{i=1}^{N}(t_i - \mathbf{w}^{T}\phi(x_i))^2$$

$\beta$从上式中可解释为响应值围绕着回归函数值的波动程度,这也与其开始的定义“噪声方差”相一致。

 

最小二乘法的几何解释

如果把响应值$$t = (t_1, t_2, ..., t_n)$$看作n维空间中的一个向量,同时将每个基函数应用于所有\( x_i, i=1...n \)形成M个基函数向量$$\bar {\phi_j}, j=1...M$$的话,最小二乘法在几何意义上就可以解释为M个基函数向量形成的线性子空间中找到一个最优向量,使其与响应向量的欧氏距离最小。

进一步地,这个最优向量实际就是响应向量在这个基函数向量所形成的子空间中的投影,最优解就是基于M个基函数向量线权加权得到这个最优向量时的参数\( w, \beta\)。

 

在线学习

如果训练数据集非常大,那么使用其对模型进行一次训练可能是极其耗时的,此时使用在线学习(或者流式学习)算法将是一种更好的选择。在这种场景下,我们让数据一个接着一个地使用,当每获取一个数据点时,就基于这个新的数据点来更新模型的参数值。

我们可以采用一种称为随机梯度下降的方式来实现在线学习。具体地,如果n个数据点的误差函数可以表示为

\[ E = \sum_n E_n \]

那么当第n个点到来时,模型参数的更新方式为

\[  \mathbf{w}^{(\tau + 1)} = \mathbf{w}^{(\tau)} - \eta \delta E_n\]

其中\(\eta\)为学习率,\(\tau\)为迭代次数。参数的初始值可以随机选。特别地,对平方误差函数,上式可表示为

\[  \mathbf{w}^{(\tau + 1)} = \mathbf{w}^{(\tau)} - \eta (t_n - {\mathbf{w}^{(\tau)}}^T \phi_n ) \phi_n \]

这个算法被称为LMS(least-mean-square)算法。

 

带有规则化项的最小二乘法

为了控制过拟合的出现,第一章中提到一种利用规则化项的方法,即最小化带有惩罚项的误差函数

\[ E_D(\mathbf{w}) + \lambda E_W(\mathbf{w})\]

其中\( \lambda \)为规则化项系数,用以控制两者之间的权衡关系。一种简单的规则化项称 二次规则化项,称为权重衰减,即

\[ E_W(\mathbf{w}) = \frac{1}{2} {\mathbf{w}}^{T} {\mathbf{w}}\]

如果将原始误差替换为平方误差,那么整个误差函数就可以表示为

\[ \frac{1}{2} \sum_{n=1}^{N} (t_n - \mathbf{w}^T \phi(x_n))^2 + \frac{\lambda}{2}{\mathbf{w}}^T {\mathbf{w}} \]

基于以上误差函数,通过最小二乘法得到的最优参数值为

\[ \mathbf{w} = (\lambda \mathbf{I} + \Phi^{T} \Phi)^{-1} \Phi^{T} \mathbf{t}\]

实际上,其就是对最小二乘结果的一个简单扩展。

更加一般的规则化项可以表达为

\[ \frac{1}{2} \sum_{j=1}^{M}{|w_j|}^{q}\]

其中当q=2的时候,即为权平方的规则化项。当q=1时,这个带规则化项的最小二乘法也称为套索(lasso),当\( \lambda \)足够大时,它可以产生一个稀疏的模型,即让多数基函数对应的系数接近于0.

本质上,规则化项方法并没有从根本上解决过拟合问题,或者模型复杂度问题,它仅仅是将问题做了转移,从寻找合适数量的基函数,变为了如何确定规则化项系数\( \lambda \)。

本章下面内容均假设规则化项为二次规则化项。

 

多维响应值

一些情况下,每个\( x_n \)所对的输出\( t_n \)并不是一维的,而是多维的。最简单的方式就是为每一个响应维度确定一组基函数,从而把问题分解为多个线性回归问题。当然,也可以选择一组相同的基函数,来应付所有的响应维度。

\[ p(\mathbf{t} | \mathbf{x}, \mathbf{W}, \beta) = N(\mathbf{t} | \mathbf{W}^T \phi(\mathbf{x}), \beta^{-1}\mathbf{I}) \] 

同样通过最小二乘法来求解,可得

\[ \mathbf{W_{ML}} = (\Phi^T \Phi)^{-1}\Phi^T\mathbf{T}\]

而每响应维度上,其对应的参数值为

\[ \mathbf{w_k} = (\Phi^T \Phi)^{-1}\Phi^T \mathbf{t_k}\]

因此,我们可以将响应维度进行解耦,我们只需要计算一次\( \Phi \),然后就可以计算任何一个维度上的参数值。>

更一般地,正态分布的协方差阵可以不是严格对角阵,而可以是任意矩阵,我们同样可以对每个响应维度进行解耦。这是因为\( \mathbf{W} \)是只与分布的均值相同,而其估计值是可以独立于协方差来估计出来的,即它是独立于协方差的。(详见第一章)

 

Avatar_small
TN Board Question Pa 说:
2022年8月20日 16:54

Tamilnadu Board Model Paper 2023 Class 7 Pdf Download with Answers for Tamil Medium, English Medium, Hindi Medium, Urdu Medium & Students for Small Answers, Long Answer, Very Long Answer Questions, and Essay Type Questions to Term1 & Term2 Exams at official website. TN Board Question Paper Class 7 New Exam Scheme or Question Pattern for Sammittive Assignment Exams (SA1 & SA2): Very Long Answer (VLA), Long Answer (LA), Small Answer (SA), Very Small Answer (VSA), Single Answer, Multiple Choice and etc.

Avatar_small
tneb online payment 说:
2022年12月16日 22:38

The Tamil Nadu Electricity Board (TNEB) was established on July 1, 1957, as a highly integrated utility responsible for generating electricity, transmission, and distribution under Section 54 of the Electricity (Supply) Act of 1948 relating to Tamil Nadu. tneb online payment State Citizens can register to pay their electricity bills and check the status of their connection along with the paid bill by registering at TANGEDCO / TNEBNET portal. This guide will explain the registration process along with Login and Status check online in a simple manner.

Avatar_small
Moneygram Money Orde 说:
2023年1月30日 16:11

MoneyGram Money Order is a prepaid amount that is fixed and anyone who has their name in the recipient can withdraw the same, and the Money Order is safe for paying the payment for any individuals, as the payment will be authentic and only they will be receiving the money. Moneygram Money Order The Money Order is not a cheque which does get a bounce or nil account, as you get the Money Order ready by paying in advance in MoneyGram and Post offices are not always available.

Avatar_small
Blueprint 2024 for 1 说:
2023年2月11日 19:15

Board of Secondary Education board will soon declare CBSE 10th Blueprint 2024 through its official website. Blueprint 2024 for 10th CBSE board will declare its Central Board of Secondary Education 10th Blueprint 2024 in the month of May this year and this board published the notification regarding the examinations of class 10th and after a few time in the month of March exams were started from March. In the previous academic session also Paper 2024.

Avatar_small
rajasthan8thresult2 说:
2023年7月01日 19:01

According to reports, this year, a sizable number of boys and girls have applied for and participated in the state's class eighth grade annual final public examination tests in Rajasthani, Hindi, and English for all students enrolled in government and private schools throughout the state. More than 12 lakh students,both boys and girls, from all rural and urban area rajasthan8thresult2019.in schools, took part. Based on previous years' Ajmer board result SMS registration.

Avatar_small
seo service london 说:
2024年1月16日 22:01

After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter