perceptron.m

来自「人工神经网络资料」· M 代码 · 共 42 行

M
42
字号
 clear
P=rand(2,50)*10;
T=zeros(1,50);
for i=1:50
if (P(1,i)<= P(2,i)) T(i)=1
end
end   

%  P=[-0.5 -0.5 1.3 0.7 10;
%     -0.5 0.5 0.5 1.0 10];
%T=[1 1 0 0  0];
net=newp(minmax(P),1,'hardlim','learnpn')

plotpv(P,T)
net.iw{1,1} = [-1 -1];
net.b{1} = 1;
linehandle=plotpc(net.IW{1},net.b{1})
pause
echo on
E=1
n=0
ep=1.0E-6;
while(sse(E)>ep)
    [net,y,E]=adapt(net,P,T)
    n=n+1
    perf(n)=sse(E)
    
   % pause
   %linehandle=plotpc(net.IW{1},net.b{1})%drawnow;
    linehandle=plotpc(net.IW{1},net.b{1},linehandle);drawnow;
    hold on
end
P1=[2 2
    1 3 ];
A=sim(net,P1)
figure(2)
plotpv(P,T)
hold on

%plotpv(P1,A)
%figure(2)
%plot(P,sin(2*pi*P),':',P,A,'B+')

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?