您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > AI人工智能 > 北科大模式识别基础实验报告
学院:自动化学院班级:姓名:学号:2014年11月模式识别基础实验2实验一Bayes分类器的设计一、实验目的:1.对模式识别有一个初步的理解,能够根据自己的设计对贝叶斯决策理论算法有一个深刻地认识;2.理解二类分类器的设计原理。二、实验条件:1.PC微机一台和MATLAB软件。三、实验原理:最小风险贝叶斯决策可按下列步骤进行:1.在已知)(iP,)|(iXP,ci,,1及给出待识别的X的情况下,根据贝叶斯公式计算出后验概率:cjjjiiiPXPPXPXP1)()|()()|()|(cj,,12.利用计算出的后验概率及决策表,按下式计算出采取i决策的条件风险:cjjjiiXPXR1)|(),()|(ai,,13.对2中得到的a个条件风险值)|(XRi(ai,,1)进行比较,找出使条件风险最小的决策k,即:)|(min)|(,,1XRXRkcik,则k就是最小风险贝叶斯决策。四、实验内容:假定某个局部区域细胞识别中正常(1)和非正常(2)两类先验概率分别为:正常状态:)(1P=0.9;异常状态:)(2P=0.1。现有一系列待观察的细胞,其观察值为x:-3.9847-3.5549-1.2401-0.9780-0.7932-2.8531模式识别基础实验3-2.7605-3.7287-3.5414-2.2692-3.4549-3.0752-3.99342.8792-0.97800.79321.18823.0682-1.5799-1.4885-0.7431-0.4221-1.11864.2532)|(1xP)|(2xP类条件概率分布正态分布分别为(-2,0.25)(2,4)。决策表为011(11表示),(ji的简写),12=6,21=1,22=0。试对观察的结果进行分类。五、实验程序及结果:试验程序和曲线如下,分类结果在运行后的主程序中:实验程序:x=[-3.9847-3.5549-1.2401-0.9780-0.7932-2.8531-2.7605-3.7287-3.5414-2.2692-3.4549-3.0752-3.99342.8792-0.97800.79321.18823.0682-1.5799-1.4885-0.7431-0.4221-1.11864.2532]pw1=0.9;pw2=0.1e1=-2;a1=0.5e2=2;a2=2m=numel(x)%得到待测细胞个数pw1_x=zeros(1,m)%存放对w1的后验概率矩阵pw2_x=zeros(1,m)%存放对w2的后验概率矩阵results=zeros(1,m)%存放比较结果矩阵fori=1:m%计算在w1下的后验概率pw1_x(i)=(pw1*normpdf(x(i),e1,a1))/(pw1*normpdf(x(i),e1,a1)+pw2*normpdf(x(i),e2,a2))%计算在w2下的后验概率pw2_x(i)=(pw2*normpdf(x(i),e2,a2))/(pw1*normpdf(x(i),e1,a1)+pw2*normpdf(x(i),e2,a2))endfori=1:mifpw1_x(i)pw2_x(i)%比较两类后验概率result(i)=0%正常细胞elseresult(i)=1%异常细胞endenda=[-5:0.05:5]%取样本点以画图n=numel(a)pw1_plot=zeros(1,n)pw2_plot=zeros(1,n)forj=1:n模式识别基础实验4pw1_plot(j)=(pw1*normpdf(a(j),e1,a1))/(pw1*normpdf(a(j),e1,a1)+pw2*normpdf(a(j),e2,a2))pw2_plot(j)=(pw2*normpdf(a(j),e2,a2))/(pw1*normpdf(a(j),e1,a1)+pw2*normpdf(a(j),e2,a2))endfigure(1)holdonplot(a,pw1_plot,'k-',a,pw2_plot,'r-.')fork=1:mifresult(k)==0plot(x(k),-0.1,'b*')%正常细胞用*表示elseplot(x(k),-0.1,'rp')%异常细胞用五角星表示end;end;legend('正常细胞后验概率曲线','异常细胞后验概率曲线','正常细胞','异常细胞')xlabel('样本细胞的观察值')ylabel('后验概率')title('后验概率分布曲线')gridonreturn模式识别基础实验5实验二基于Fisher准则的线性分类器设计一、实验目的:1.进一步了解分类器的设计概念,能够根据自己的设计对线性分类器有更深刻地认识;2.理解Fisher准则方法确定最佳线性分界面方法的原理,以及拉格朗日乘子求解的原理。二、实验条件:1.PC微机一台和MATLAB软件。三、实验原理:设有一个集合包含N个d维样本Nxxx,,,21,其中1N个属于1类,2N个属于2类。线性判别函数的一般形式可表示成0)(wxWxgT,其中Td),,(1。根据Fisher选择投影方向W的原则,即使原样本向量在该方向上的投影能兼顾类间分布尽可能分开,类内样本投影尽可能密集的要求,用以评价投影方向W的函数为:WSWWSWWJwTbTF)(TWmmSW)(211*其中:iNjjiixNm112,1ijx为iN类中的第j个样本wS为类内离散度,定义为:2111))((iNjTijjwimxmxSbS为类间离散度,定义为:TbmmmmS))((2121上面的公式是使用Fisher准则求最佳法线向量的解,我们称这种形式的运算为线性变换,其中)(21mm是一个向量,1WS是WS的逆矩阵,如)(21mm是d维,1WS和WS都是d×d维,得到的*W也是一个d维的向量。向量*W就是使Fisher准则函数)(WJF达极大值的解,也就是按Fisher准则将d维X空间投影到一维Y空间的最佳投影方向,该向量*W的各分量值是对原模式识别基础实验6d维特征向量求加权和的权值。以上讨论了线性判别函数加权向量W的确定方法,并讨论了使Fisher准则函数极大的d维向量*W的计算方法,但是判别函数中的另一项0w尚未确定,一般可采用以下几种方法确定0w如2)(21*0mmWwT或者212211*0)(NNmNmNWwT或当)(1P与)(2P已知时可用*1212012()ln[()/()][]22TWmmPPwNN当0w确定之后,则可按以下规则分类,*010TWXwx*020TWXwx四、实验内容:已知有两类数据1和2二者的概率已知)(1P=0.6,)(2P=0.4。1中数据点的坐标对应一一如下:1x=0.23311.52070.64990.77571.05241.19740.29080.25180.66820.56220.90230.1333-0.54310.9407-0.21260.0507-0.08100.73150.33451.0650-0.02470.10430.31220.66550.58381.16531.26530.8137-0.33990.51520.7226-0.20150.4070-0.1717-1.0573-0.20991y=2.33852.19461.67301.63651.78442.01552.06812.12132.47971.51181.96921.83401.87042.29481.77142.39391.56481.93292.20272.45681.75231.69912.48831.72592.04662.02262.37571.79872.08282.07981.94492.38012.23732.16141.92352.2604模式识别基础实验71z=0.53380.85141.08310.41641.11760.55360.60710.44390.49280.59011.09271.07561.00720.42720.43530.98690.48411.09921.02990.71271.01240.45760.85441.12750.77050.41291.00850.76760.84180.87840.97510.78400.41581.03150.75330.95482数据点的对应的三维坐标为:2x=1.40101.23012.08141.16551.37401.18291.76321.97392.41522.58902.84721.95391.25001.28641.26142.00712.18311.79091.33221.14661.70871.59202.93531.46642.93131.83491.83402.50962.71982.31482.03532.60301.23272.14651.56732.94142y=1.02980.96110.91541.49010.82000.93991.14051.06780.80501.28891.46011.43340.70911.29421.37440.93871.22661.18330.87980.55920.51500.99830.91200.71261.28331.10291.26800.71401.24461.33921.18080.55031.47081.14350.76791.12882z=0.62101.36560.54980.67080.89321.43420.95080.73240.57841.49431.09150.76441.21591.30491.14080.93980.61970.66031.39281.40840.69090.84000.53811.37290.77310.73191.34390.81420.95860.73790.75480.73930.67390.86511.36991.1458数据的样本点分布如下图:-2-101230.511.522.500.511.52根据所得结果判断(1,1.5,0.6)(1.2,1.0,0.55),(2.0,0.9,0.68),(1.2,1.5,0.89),(0.23,2.33,1.43),属于哪个类别。模式识别基础实验8五、实验程序及结果:x1=[0.23311.52070.64990.77571.05241.19740.29080.25180.66820.56220.90230.1333-0.54310.9407-0.21260.0507-0.08100.73150.33451.0650-0.02470.10430.31220.66550.58381.16531.26530.8137-0.33990.51520.7226-0.20150.4070-0.1717-1.0573-0.2099];y1=[2.33852.19461.67301.63651.78442.01552.06812.12132.47971.51181.96921.83401.87042.29481.77142.39391.56481.93292.20272.45681.75231.69912.48831.72592.04662.02262.37571.79872.08282.07981.94492.38012.23732.16141.92352.2604];z1=[0.53380.85141.08310.41641.11760.55360.60710.44390.49280.59011.09271.07561.00720.42720.43530.98690.48411.09921.02990.71271.01240.45760.85441.12750.77050.41291.
本文标题:北科大模式识别基础实验报告
链接地址:https://www.777doc.com/doc-2069094 .html