模式识别实验2.docx
- 文档编号:4725281
- 上传时间:2022-12-08
- 格式:DOCX
- 页数:16
- 大小:17.37KB
模式识别实验2.docx
《模式识别实验2.docx》由会员分享,可在线阅读,更多相关《模式识别实验2.docx(16页珍藏版)》请在冰豆网上搜索。
模式识别实验2
附录一:
线性识别IRIS数据
源代码如下:
实验结果可以很好分开数据。
DATE0=[5.1,3.5,1.4,0.2;...
4.9,3.0,1.4,0.2;...
4.7,3.2,1.3,0.2;...
4.6,3.1,1.5,0.2;...
5.0,3.6,1.4,0.2;...
5.4,3.9,1.7,0.4;...
4.6,3.4,1.4,0.3;...
5.0,3.4,1.5,0.2;...
4.4,2.9,1.4,0.2;...
4.9,3.1,1.5,0.1;...
5.4,3.7,1.5,0.2;...
4.8,3.4,1.6,0.2;...
4.8,3.0,1.4,0.1;...
4.3,3.0,1.1,0.1;...
5.8,4.0,1.2,0.2;...
5.7,4.4,1.5,0.4;...
5.4,3.9,1.3,0.4;...
5.1,3.5,1.4,0.3;...
5.7,3.8,1.7,0.3;...
5.1,3.8,1.5,0.3;...
5.4,3.4,1.7,0.2;...
5.1,3.7,1.5,0.4;...
4.6,3.6,1.0,0.2;...
5.1,3.3,1.7,0.5;...
4.8,3.4,1.9,0.2;...
5.0,3.0,1.6,0.2;...
5.0,3.4,1.6,0.4;...
5.2,3.5,1.5,0.2;...
5.2,3.4,1.4,0.2;...
4.7,3.2,1.6,0.2;...
4.8,3.1,1.6,0.2;...
5.4,3.4,1.5,0.4;...
5.2,4.1,1.5,0.1;...
5.5,4.2,1.4,0.2;...
4.9,3.1,1.5,0.2;...
5.0,3.2,1.2,0.2;...
5.5,3.5,1.3,0.2;...
4.9,3.6,1.4,0.1;...
4.4,3.0,1.3,0.2;...
5.1,3.4,1.5,0.2;...
5.0,3.5,1.3,0.3;...
4.5,2.3,1.3,0.3;...
4.4,3.2,1.3,0.2;...
5.0,3.5,1.6,0.6;...
5.1,3.8,1.9,0.4;...
4.8,3.0,1.4,0.3;...
5.1,3.8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1;
S1=zeros(100,4);p1=1;
fori=1:
1:
100
s=x(:
i);
sx=s-ave;%ʶ±ð֮ǰÇóÌØÕ÷Öµ
ifw'*sx<0
S0(p0,:
)=s';p0=p0+1;
else
S1(p1,:
)=s';p1=p1+1;
end
end
附录二线性识别IRIS数据梯度向量法求最优
源代码如下:
输入数据代码如上,略。
x0=DATE0';
x1=DATE1';
sum=zeros(4,1);
x=ones(4,100);
y=0.9*ones(1,100);
fori=1:
1:
50
x(:
i)=x0(:
i);
x(:
i+50)=x1(:
i);
y(i)=0.1;
end
w=zeros(4,1);
b=0;
fort=1:
1:
100%%%%%%%%%%%%%%%%%%%%%%%%
db=0;
dw=zeros(4,1);
fori=1:
1:
100
db=db+2*(w'*x(:
i)+b-y(i));
end
dw=2*x*(x'*w+b*ones(100,1)-y');
r=0.0001;
s=0.0001;
w=w-r*dw;
b=b-s*db;
end
S0=zeros(100,4);p0=1;
S1=zeros(100,4);p1=1;
fori=1:
1:
100
s=x(:
i);
ifw'*x+b<0
S0(p0,:
)=s';p0=p0+1;
else
S1(p1,:
)=s';p1=p1+1;
end
end
附录三神经网络仿真异或门
源代码如下:
X=[0,0,1,1;0,1,0,1];
d=[0.1,0.9,0.9,0.1];
O1=zeros(2,4);
O2=zeros(2,4);
O3=zeros(1,4);
dw1=ones(2,2);
dw2=ones(2,2);
dw3=ones(1,2);
KS3=zeros(size(O3));%KS3=zeros(1,4)
KS2=zeros(size(O2));%KS2=zeros(2,4)
KS1=zeros(size(O1));%KS1=zeros(2,4)
w1=[7.93,100;101,92];b1=[5.8;9.09];
w2=[4,6;7,9.6];b2=[9.5;3.8];
w3=[4.8,91];b3=ones(1,1);
fort=1:
1:
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(d-O3)*(d-O3)'>0.1
%Çó¸÷¸öÑù±¾¶ÔÓ¦µÄÊä³ö
fori=1:
1:
4
x=X(:
i);
i1=w1*x+b1;
o1=1./(1.+exp(-i1));
i2=w2*o1+b2;
o2=1./(1.+exp(i2));
i3=w3*o2+b3;
o3=1./(1.+exp(-i3));
O1(:
i)=o1;
O2(:
i)=o2;
O3(:
i)=o3;
end
(d-O3)*(d-O3)'
%ÇóKS3
KS3=zeros(size(O3));
fori=1:
1:
1
fork=1:
1:
4
KS3(i,k)=2*(O3(i,k)-d(i,k))*O3(i,k)*(1-O3(i,k));
end
end
%¼ÆËãKS2
KS2=zeros(size(O2));
fori=1:
1:
2
fork=1:
1:
4
forww=1:
1:
1
KS2(i,k)=KS2(i,k)+w3(ww,i)*KS3(ww,k);
end
KS2(i,k)=KS2(i,k)*O2(i,k)*(1-O2(i,k));
end
end
%¼ÆËãKS1
KS1=zeros(size(O1));
fori=1:
1:
2
fork=1:
1:
4
forww=1:
1:
2
KS1(i,k)=KS1(i,k)+w2(ww,i)*KS2(ww,k);
end
KS1(i,k)=KS1(i,k)*O1(i,k)*(1-O1(i,k));
end
end
%¼ÆËãÌݶÈdw3
fori=1:
1:
1
forj=1:
1:
2
dw3(i,j)=KS3(i,:
)*O2(j,:
)';%fork=1:
1:
4dw3(i,j)=dw3(i,j)+KS3(i,k)*O2(j,k);
end
end
%¼ÆËãÌݶÈdw2
fori=1:
1:
2
forj=1:
1:
2
dw2(i,j)=KS2(i,:
)*O1(j,:
)';
end
end
%¼ÆËãÌݶÈdw1
fori=1:
1:
2
forj=1:
1:
2
dw1(i,j)=KS1(i,:
)*X(j,:
)';
end
end
%¼ÆËãdb3
db3=zeros(1,1);
fori=1:
1:
1
fork=1:
1:
4
db3(i)=db3(i)+KS3(i,k);
end
end
%¼ÆËãdb2
db2=zeros(2,1);
fori=1:
1:
2
fork=1:
1:
4
db2(i)=db2(i)+KS2(i,k);
end
end
%¼ÆËãdb2
db1=zeros(2,1);
fori=1:
1:
2
fork=1:
1:
4
db1(i)=db1(i)+KS1(i,k);
end
end
%¸üÐÂw,b
a=0.1;
w3=w3-a*dw3;
w2=w2-a*dw2;
w1=w1-a*dw1;
b3=b3-a*db3;
b2=b2-a*db2;
b1=b1-a*db1;
end
附录四神经网络识别IRIS数据
源代码如下:
数据输入同上,略
x0=DATE0';
x1=DATE1';
X=ones(4,100);
d=0.9*ones(1,100);
fori=1:
1:
50
X(:
i)=x0(:
i);
X(:
i+50)=x1(:
i);
d(i)=0.1;
end
O1=zeros(2,100);I1=zeros(2,100);
O2=zeros(2,100);I2=zeros(2,100);
O3=zeros(1,100);I3=zeros(1,100);
dw1=ones(2,4);
dw2=ones(2,2);
dw3=ones(1,2);
KS3=zeros(size(O3));%KS3=zeros(1,100)
KS2=zeros(size(O2));%KS2=zeros(2,100)
KS1=zeros(size(O1));%KS1=zeros(2,100)
w1=[0.01,0.36,0.49,0.63;0.79,2.46,1.3,00.36];b1=[5.8;9.09];
w2=[4,6;7,9.6];b2=[9.5;3.8];
w3=[4.8,0.91];b3=ones(1,1);
fort=1:
1:
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(d-O3)*(d-O3)'>0.1
%Çó¸÷¸öÑù±¾¶ÔÓ¦µÄÊä³ö
fori=1:
1:
100
x=X(:
i);
i1=w1*x+b1;
o1=1./(1.+exp(-i1));
i2=w2*o1+b2;
o2=1./(1.+exp(i2));
i3=w3*o2+b3;
o3=1./(1.+exp(-i3));
O1(:
i)=o1;I1(:
i)=i1;
O2(:
i)=o2;I2(:
i)=i2;
O3(:
i)=o3;I3(:
i)=i3;
end
(d-O3)*(d-O3)'
%ÇóKS3
KS3=zeros(size(O3));
fori=1:
1:
1
fork=1:
1:
100
KS3(i,k)=2*(O3(i,k)-d(i,k))*O3(i,k)*(1-O3(i,k));
end
end
%¼ÆËãKS2
KS2=zeros(size(O2));
fori=1:
1:
2
fork=1:
1:
100
forww=1:
1:
1
KS2(i,k)=KS2(i,k)+w3(ww,i)*KS3(ww,k);
end
KS2(i,k)=KS2(i,k)*O2(i,k)*(1-O2(i,k));
end
end
%¼ÆËãKS1
KS1=zeros(size(O1));
fori=1:
1:
2
fork=1:
1:
100
forww=1:
1:
2
KS1(i,k)=KS1(i,k)+w2(ww,i)*KS2(ww,k);
end
KS1(i,k)=KS1(i,k)*O1(i,k)*(1-O1(i,k));
end
end
%¼ÆËãÌݶÈdw3
fori=1:
1:
1
forj=1:
1:
2
dw3(i,j)=KS3(i,:
)*O2(j,:
)';%fork=1:
1:
4dw3(i,j)=dw3(i,j)+KS3(i,k)*O2(j,k);
end
end
%¼ÆËãÌݶÈdw2
fori=1:
1:
2
forj=1:
1:
2
dw2(i,j)=KS2(i,:
)*O1(j,:
)';
end
end
%¼ÆËãÌݶÈdw1
fori=1:
1:
2
forj=1:
1:
4
dw1(i,j)=KS1(i,:
)*X(j,:
)';
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%¼ÆËãdb3
db3=zeros(1,1);
fori=1:
1:
1
fork=1:
1:
100
db3(i)=db3(i)+KS3(i,k);
end
end
%¼ÆËãdb2
db2=zeros(2,1);
fori=1:
1:
2
fork=1:
1:
100
db2(i)=db2(i)+KS2(i,k);
end
end
%¼ÆËãdb2
db1=zeros(2,1);
fori=1:
1:
2
fork=1:
1:
100
db1(i)=db1(i)+KS1(i,k);
end
end
%¸üÐÂw,b
a=0.1;
w3=w3-a*dw3;
w2=w2-a*dw2;
w1=w1-a*dw1;
b3=b3-a*db3;
b2=b2-a*db2;
b1=b1-a*db1;
end
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 模式识别 实验
![提示](https://static.bdocx.com/images/bang_tan.gif)