用单层感知器对数据进行分类处理:
%单层感知器
%输入向量
P=[1.24 1.36 1.38 1.38 1.38 1.40 1.48 1.54 1.56 1.14 1.18 1.2 1.26 1.28 1.3;
1.72 1.74 1.64 1.82 1.9 1.7 1.82 1.82 2.08 1.78 1.96 1.86 2.0 2.0 1.96];
%目标向量
T=[1 1 1 1 1 1 1 1 1 0 0 0 0 0 0];
plotpv(P,T);
%建立感知器
net=newp([0,3;0,3],1);
%初始化感知器
net=init(net);
net.iw{1,1};
net.b{1};
linehandle=plotpc(net.iw{1,1},net.b{1});
E=1;
%修正感知器网络
while(sse(E))
%返回学习后的网络 Y为输出 E为误差
[net,Y,E]=adapt(net,P,T);
%分界线绘制函数
linehandle=plotpc(net.iw{1},net.b{1},linehandle);
%更新分割线
drawnow;
end;
%用训练好的感知器对未知类别样本分类
p=[1.24,1.28,1.4;1.8,1.84,2.04];
%开始模拟
a=sim(net,p);
plotpv(p,a);
ThePoint=findobj(gca,'type','line');
set(ThePoint,'Color','red');
hold on;
plotpv(P,T);
plotpc(net.iw{1},net.b{1});
hold off;
disp('End of percept');
%单层感知器
%输入向量
P=[1.24 1.36 1.38 1.38 1.38 1.40 1.48 1.54 1.56 1.14 1.18 1.2 1.26 1.28 1.3;
1.72 1.74 1.64 1.82 1.9 1.7 1.82 1.82 2.08 1.78 1.96 1.86 2.0 2.0 1.96];
%目标向量
T=[1 1 1 1 1 1 1 1 1 0 0 0 0 0 0];
%建立感知器
net=newp([0,3;0,3],1);
%网络训练次数定义
net.adaptParam.passes=100;
%返回自适应的神经网络
net=adapt(net,P,T);
%输出仿真结果
Y=sim(net,P)
%用训练好的感知器对未知类别样本分类
p=[1.24,1.28,1.4;1.8,1.84,2.04];
%开始模拟
a=sim(net,p)