%single neuron delta training with soft activation function % BATCH training with several patterns format compact; clear all; ip= [-1,-1; 2,2; 0,0; 1,1; -0.5,0; 2,1; 0,1; 3,1; 1,1.5; 2.5,1.5] ip= [-1,-1; 2,2; 0,0; 1,1; -0.5,0; 2,1; 0,1; 3,1; 1,2; 3,2] [np,ni]=size(ip); ip(:,ni+1)=ones(np,1) %augmenting input dp=[-1, 1,-1, 1, -1, 1, -1, 1, -1, 1]', ww=[-1 3 -3], c=1; k=1; figure(1); clf; hold on; xlabel('X input'); ylabel('Y input'); a=axis ; a=[-2 4 -2 4]; axis(a);j=0; for ite=1:10000, if ite>1, plot(x,y,'g'); end; net=ip*ww'; op=tanh(0.5.*k.*net); fp=k.*(1-op.*op); er=dp-op; dw=(c*er.*fp)'*ip; ww=ww+dw; x(1)=-2; y(1)=-(ww(1)*x(1)+ww(3))./ww(2); x(2)=4; y(2)=-(ww(1)*x(2)+ww(3))./ww(2); plot(x,y,'r'); % pause; ter=er'*er, tter(ite)=ter; if ter <0.01, break; end; end; for p=1:np, if dp(p)>0, plot(ip(p,1),ip(p,2),'ro'); else plot(ip(p,1),ip(p,2),'bx'); end; end; hold off; ite figure(2); clf; semilogy(tter); xlabel('iterations'); ylabel('error');