感知机章节课后习题 + 证明感知机算法收敛性
2013-07-04 23:40
465 查看
看了下统计学习方法P36 的3个习题,试着做了下,下面给出自己的解答: 有不对的地方欢迎提出:)
Q 2.1 感知机是线性模型,因此不能表示复杂的函数。请解释感知机为什么不能学习异或XOR函数?
A 2.1 XOR:这个想必大家都很清楚了,输入的两个逻辑值一真一假XOR结果为真,两个输入逻辑值同真同假XOR得假。
下面这个图解释的很清楚:
训练集线性不可分,当然不能用感知机表示出XOR函数。
Q 2.2 模仿书中2.1例,构建从训练数据集合求解感知机的例子
A 2.2 可以构建一个3维的特征空间,取在I卦限的任意两点为正例,取其在第VII卦限一点为负例,比如可以这么取:
正例:(1,1,1) (2,5,7)
负例: (-2,-1,-1)
使用感知机原始形式求解:
Round 1 : Flase-Classified Point: 3 ,w1: 2 ,w2: 1 ,w3: 1 ,b: -1
Theperceptron model learned is sign(2 x1 + 1 x2 + 1 x3 + -1)
Q 2.3 一道证明题,暂略~ 周末有空了做下~
-----------------------------------proof of divergence theorem 2.1----------------------------------
好长时间不写字了,这笔迹真是不忍直视啊....
Q 2.1 感知机是线性模型,因此不能表示复杂的函数。请解释感知机为什么不能学习异或XOR函数?
A 2.1 XOR:这个想必大家都很清楚了,输入的两个逻辑值一真一假XOR结果为真,两个输入逻辑值同真同假XOR得假。
下面这个图解释的很清楚:
训练集线性不可分,当然不能用感知机表示出XOR函数。
Q 2.2 模仿书中2.1例,构建从训练数据集合求解感知机的例子
A 2.2 可以构建一个3维的特征空间,取在I卦限的任意两点为正例,取其在第VII卦限一点为负例,比如可以这么取:
正例:(1,1,1) (2,5,7)
负例: (-2,-1,-1)
使用感知机原始形式求解:
import os import sys import random #This algorithm learns a perceptron model from trainingdataset #note: the trainset is linearly seperable, and different choicesof initial parameters or false-classified points #may lead to different perceptron model, which is reasonableunder this framework. #DATE:2013-7-4, by zhl if __name__ == "__main__": trainset =[(1,1,1,1),(2,5,7,1),(-2,-1,-1,-1)] #initialize w1 = w2 = w3 = b = 0 id = 0 # we set learning rate = 1 while True: id += 1 flag = False for choice in range(3): if trainset[choice][3] * (w1 * trainset[choice][0] + w2 * trainset[choice][1] + w3 * trainset[choice][2] + b)<= 0: flag = True break if flag == False: break #randomlyselect a point from trainset choice = random.randint(0,2) #judge whether it's false-classified if trainset[choice][3] * (w1 *trainset[choice][0] + w2 * trainset[choice][1] + w3 * trainset[choice][2] + b) <= 0: w1 = w1 + trainset[choice][3] * trainset[choice][0] w2 = w2 + trainset[choice][3] * trainset[choice][1] w3 = w3 + trainset[choice][3] * trainset[choice][2] b = b + trainset[choice][3] #print out current values print 'Round ',id,':','Flase-Classified Point:',choice + 1,',w1:',w1,',w2:',w2,',w3:',w3,',b:',b,'\n' print 'Theperceptron model learned is sign(%d x1 + %d x2 + %d x3 + %d)\n' % (w1,w2,w3,b)
Round 1 : Flase-Classified Point: 3 ,w1: 2 ,w2: 1 ,w3: 1 ,b: -1
Theperceptron model learned is sign(2 x1 + 1 x2 + 1 x3 + -1)
Q 2.3 一道证明题,暂略~ 周末有空了做下~
-----------------------------------proof of divergence theorem 2.1----------------------------------
好长时间不写字了,这笔迹真是不忍直视啊....
相关文章推荐
- [算法作业] Chapter 8 NP-complete problems 课后习题部分证明
- 算法:一个NP问题的证明(课后习题)
- 感知器学习算法PLA的收敛性证明
- 算法提高 ADV-212 3-1课后习题2
- 《数据结构与算法分析:C语言描述_原书第二版》CH2算法分析_课后习题_部分解答
- 机器学习【周志华】课后习题2.5证明
- 算法课习题证明
- NP完全问题的证明-算法概论课后习题8.15
- c++primer第四版第三章课后习题的几个解答算法
- 大一上:计算机导论复习(每章分值、常考题型以及部分章节课后习题答案【网上没有,老师自己做的】)
- 课后习题8.3-证明
- 【算法竞赛入门经典】【第三章】课后习题(第二部分)
- 算法概论8章,部分习题证明
- 15算法课程 课后习题8.3
- 算法(第四版)课后习题(1.3.18~1.3.28)
- 算法竞赛入门经典课后习题答案:第一章(C++解法)
- 蓝桥杯 ADV-212 算法提高 3-1课后习题2
- 【算法概论】第八章课后习题
- 算法第四版 课后习题答案
- 算法概论习题:8.14NP-完全问题的证明