%single neuron LMS traning with soft activation function format compact; clear all; ip=[1 2; 2 1] dp=[-1,1]' ww=[1 3 -3] c=0.1; k=1; figure(1); clf; hold on; xlabel('X input'); ylabel('Y input'); plot(ip(1,1),ip(1,2),'ro'); plot(ip(2,1),ip(2,2),'bx'); [np,ni]=size(ip); ip(:,ni+1)=ones(np,1) %agumenting input a=axis ; a=[0 4 0 4]; axis(a); j=0; for ite=1:1000, if ite>1, plot(x,y,'g'); end; net=ip*ww' op=tanh(0.5.*k.*net); fp=k.*(1-op.*op); er=dp-net; dw=(c*er)'*ip; ww=ww+dw; x(1)=-1; 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.001, break; end; end; hold off ite figure(2); clf; semilogy(tter); xlabel('iterations'); ylabel('error');