Asked by A SANTOSH KUMAR
on 5 Feb 2013

clc(); v=[0.197 0.3191 -0.1488 0.3394;0.3099 0.1904 -0.0347 -0.4861]; v1=zeros(2,4); b1=[-0.3378 0.27781 0.2859 -0.3329]; b2=-0.1401; w=[0.3919;-0.2913;-0.3979;0.3581]; w1=zeros(4,1); x=[1 1 0 0;1 0 1 0]; t=[0 1 1 0]; alpha=0.02; mf=0.9; con=5385; epoch=0; while con>0 e=0; for I=1:4 for j=1:4 zin=b1; for i=1:2 zin(j)=zin(j)+x(i,I)*v(i,j); end z(j)=1/(1+exp(-zin(j))); end z; for i=1:4 yin=b2+z*w; end yin; y(I)=1/(1+exp(-yin)); for I=1:4 deltak=(t(I)-y(I))*y(I); end deltaw=alpha*deltak*z(j)+mf*(w-w1); deltab2=alpha*deltak; deltainj=deltak*w; for j=1:4 deltaj(j,1)=deltainj(j,1)*z(j); end for j=1:4 for i=1:2 deltav(i,j)=alpha*deltaj(j,1)*x(i,I)+mf*(v(i,j)-v1(i,j)); end end deltav; deltab1=alpha*deltaj; w1=w; v1=v; w=w+deltaw; b2=b2+deltab2; v=v+deltav; b1=b1+deltab1'; e=e+(t(I)-y(I))^2; end con=con-1 epoch=epoch+1; end disp('BPN for XOR function with binary input and output'); disp('Final Weight Matrix and Bias'); e v b1 w b2 the output for the above program is

BPN for XOR function with binary input and output Final Weight Matrix and Bias

e =

3.0892e-004

v =

1.9700 3.1910 -1.4880 3.3940 3.0990 1.9040 -0.3470 -4.8610

b1 =

-0.9359 0.9811 0.7207 -0.5950

w =

2.9807 -3.8513 -4.9173 2.6427

b2 =

-0.3955 which is wrong. The expected out put is Output BPN for XOR funtion with Binary Input and Output Total Epoch Performed 5385 Error 0.0050 Final Weight matrix and bias v = 4.4164 4.4836 2.6086 4.0386 4.5230 –2.1693 –1.1147 –6.6716 b1 = – 0.9262 0.5910 0.6254 -1.0927 w = 6.9573 –5.5892 –5.2180 7.7782 b2 = –0.3536

*No products are associated with this question.*

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## José-Luis (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/62320#comment_127254

Any particular reason anyone should do your work? I would recommend you learn to use the debugger, go through your code line by line and try to locate the errors yourself. People in this forum are more than willing to help but please show some effort on your part.