%single neuron perceptron traning with soft activation function format compact; clear all; ip=[1 2; 2 1]; dp=[-1,1]'; ww=[1 3 -3]; c=3; k=0.3; 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:20, for p=1:np, j=j+1; if j>1, plot(x,y,'g'); end; net(p)=ip(p,:)*ww' ; op(p)=tanh(k*0.5*net(p)); %hiperbolic function er(p)=dp(p)-op(p); ww=ww+c*er(p)*ip(p,:); 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; end ter=sqrt(er*er'), tter(ite)=ter; if ter <0.0001, break; end; end; hold off; ite figure(2); clf; semilogy(tter); xlabel('iterations'); ylabel('error');