第5章:线性判别函数第一部分:计算与证明1. 有四个来自于两个类别的二维空间中的样本,其中第一类的两个样本为(1,4)T 和(2,3)T ,第二类的两个样本为(4,1)T 和(3,2)T 。
这里,上标T 表示向量转置。
假设初始的权向量a=(0,1)T ,且梯度更新步长ηk 固定为1。
试利用批处理感知器算法求解线性判别函数g(y)=a T y 的权向量。
解:首先对样本进行规范化处理。
将第二类样本更改为(4,1)T 和(3,2)T . 然后计算错分样本集:g(y 1) = (0,1)(1,4)T = 4 > 0 (正确) g(y 2) = (0,1)(2,3)T = 3 > 0 (正确) g(y 3) = (0,1)(-4,-1)T = -1 < 0 (错分) g(y 4) = (0,1)(-3,-2)T = -2 < 0 (错分) 所以错分样本集为Y={(-4,-1)T , (-3,-2)T }.接着,对错分样本集求和:(-4,-1)T +(-3,-2)T = (-7,-3)T第一次修正权向量a ,以完成一次梯度下降更新:a=(0,1)T + (-7,-3)T =(-7,-2)T 再次计算错分样本集:g(y 1) = (-7,-2)(1,4)T = -15 < 0 (错分) g(y 2) = (-7,-2)(2,3)T = -20 < 0 (错分) g(y 3) = (-7,-2)(-4,-1)T = 30 > 0 (正确) g(y 4) = (-7,-2)(-3,-2)T = 25 > 0 (正确) 所以错分样本集为Y={(1,4)T , (2,3)T }.接着,对错分样本集求和:(1,4)T +(2,3)T = (3,7)T第二次修正权向量a ,以完成二次梯度下降更新:a=(-7,-2)T + (3,7)T =(-4,5)T 再次计算错分样本集:g(y 1) = (-4,5)(1,4)T = 16 > 0 (正确) g(y 2) = (-4,5)(2,3)T = 7 > 0 (正确) g(y 3) = (-4,5)(-4,-1)T = 11 > 0 (正确) g(y 4) = (-4,5)(-3,-2)T = 2 > 0 (正确)此时,全部样本均被正确分类,算法结束,所得权向量a=(-4,5)T 。
2. 在线性感知算法中,试证明引入正余量b 以后的解区(a T y i ≥b)位于原来的解区之中(a T y i >0),且与原解区边界之间的距离为b/||y i ||。
证明:设a*满足a T y i ≥b,则它一定也满足a T y i >0,所以引入余量后的解区位于原来的解区a T y i >0之中。
注意,a T y i ≥b 的解区的边界为a T y i =b,而a T y i >0的解区边界为a T y i =0。
a T y i =b 与a T y i =0两个边界之间的距离为b/||y i ||。
(因为a T y i =0过坐标原点,相关于坐标原点到a T y i =b 的距离。
) 3. 试证明感知器准则函数正比于被错分样本到决策面的距离之和。
证明:感知器准则函数为:()()TYJ ∈=-∑y a a y决策面方程为a T y=0。
当y 为错分样本时,有a T y ≤0。
此时,错分样本到决策面的距离为a T y/||a||。
所有样本到决策面的距离之和为()T Yr ∈=-∑y a y a结论得证。
4. 对于多类分类情形,考虑one -vs -all 技巧,即构建 c 个线性判别函数:0(),1,2,...,T i i i g w i c =+=x w x , 此时的决策规则为:对 j ≠ i , 如果 g i (x ) > g j (x ), x 则被分类 ωi 类。
现有三个二维空间内的模式分类器,其判别函数为g 1(x ) = -x 1 + x 2g 2(x ) = x 1 + x 2 -1 g 3(x ) = -x 2试画出决策面,指出为何此时不存在分类不确定性区域。
解:根据上述决策规则,属于第一类 ω1的区域应满足:g 1(x ) > g 2(x ) 且g 1(x ) > g 3(x ) 所以ω1的决策界面为: g 1(x ) - g 2(x ) = -2x 1 + 1 = 0。
g 1(x ) - g 3(x ) = -x 1 + 2x 2 = 0。
同样地,属于第二类 ω2的区域应满足:g 2(x ) > g 1(x ) 且g 2(x ) > g 3(x ) 所以ω2的决策界面为: g 2(x ) - g 1(x ) = 2x 1 - 1 = 0。
g 2(x ) - g 3(x ) = x 1 + 2x 2 - 1 = 0。
属于第三类 ω3的区域应满足:g 3(x ) > g 1(x ) 且g 3(x ) > g 2(x ) 所以ω2的决策界面为: g 3(x ) - g 1(x ) = x 1 - 2x 2 = 0。
g 2(x ) - g 3(x ) = -x 1 - 2x 2 + 1 = 0。
由于三个决策边界交于一点,因此,不存在不确定性区域。
这是因为直线g 1(x )-g 2(x )=0x ) - g 1(x ) - 2x 2 = 0g 2(x ) - g 3(x ) =x 1 + 2x 2-ω1与直线g 1(x )-g 3(x )=0的交点一定位于 g 1(x )-g 2(x ) - (g 1(x )-g 3(x )) = g 2(x )-g 3(x ) =0的直线上,即g 2(x )-g 3(x ) =0过它们的交点。
5. 已知模式样本集:ω1 = {(0,0)T , (1,1)T }, ω2 = {(0,1)T , (1,0)T }。
采用误差平方准则算法(即Ho -kashyap 算法)验证它是线性不可分的。
(提示:迭代时ηk 固定取1,初始b=(1,1,1,1)T )解:首先对第二类样本,进行齐次表示,然后再进行规范化表示,得到如下规范化增广训练数据矩阵:001111011101⎛⎫ ⎪⎪= ⎪-- ⎪--⎝⎭Y Y 的伪逆矩阵为:122221()222243111T T+---⎛⎫⎪==-- ⎪ ⎪---⎝⎭Y Y Y Y进行第一次迭代a=Y +b=(0,0,0)T 计算误差e=Ya -b=(-1,-1,-1,-1) T此时,不必再更新b 即可知道不等式组Ya>0无解。
因为e 中部分元素为负(此时全为负)。
根据Ho -kashyap 算法相关(收敛性)原理,可知原样本集线性不可分。
6. Consider the hyperplane used in discrimination:(a) Show that the distance from the hyperplane g (x ) = w T x + w 0 = 0 to the point x a is|g (x a )|/||w || by minimizing ||x -x a ||2 subject to the constraint g (x ) = 0. (提示需要证明两点:其一,点x a 到超平面g (x ) = 0的距离为|g (x a )|/||w ||;其二,该距离是位于超平面g (x ) = 0上使目标函数||x -x a ||2最小的点x 到点x a 的距离。
)(b) Show that the projection of x a onto the hyperplane is given by (即证明点x a 到超平面g (x )= 0的投影x p 为如下公式):2()||||a p a g =-x x x w w 证明注意,在以下表达中,x要换成x a(b) 根据对(a)的证明的第二个公式,结论显然成立。
第二部分:计算机编程题本章所使用的数据:1.Write a program to implement the “batch perception” algorithm (see page 44 or 45 in PPT).(a). Starting with a = 0, apply your program to the training data from ω1 and ω2. Notethat the number of iterations required for convergence(即记录下收敛的步数)。
(b). Apply your program to the training data from ω3and ω2. Again, note that thenumber of iterations required for convergence.(c). Explain the difference between the iterations required in the two cases.2. Implement the Ho-Kashyap algorithm and apply it to the training data from ω1 and ω3. Repeat to apply it to the training data from ω2and ω4. Point out the training errors, and give some analyses.3. Consider relaxation methods as described in the PPT. (See the slides for the "Batch Relaxation with Margin" algorithm and page 62 in PPT for the "Single Sample Relaxation with Margin" algorithm):(a) Implement the batch relaxation with margin, set b = 0.1 and initialize a = 0, and apply it to the data in ω1and ω3. Plot the criterion function as a function of the number of passes through the training set.(b) Repeat for b = 0.5 and a0= 0(namely, initialize a= 0). Explain qualitatively any differences you find in the convergence rates.(c) Modify your program to use single sample learning. Again, Plot the criterion function as afunction of the number of passes through the training set.。