<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
clc; clear; close all;
x1=[0 0 1 1];
x2=[0 1 0 1];
t=[0 1 1 0];
v=[0.2 0.4;0.3 0.1; 0.7 0.8];
w=[0.5 0.5 0.5];
bh1=0.2;
bh2=0.6;
bh3=0.3;
bo1=0.1;
eta=0.4;
E=0;
for N=1:10000
for i=1:4
uh1=x1(i)*v(1,1)+x2(i)*v(1,2)+bh1;
uh2=x1(i)*v(2,1)+x2(i)*v(2,2)+bh1;
uh3=x1(i)*v(3,1)+x2(i)*v(3,2)+bh1;
y1=1/(1+exp(-uh1));
y2=1/(1+exp(-uh2));
y3=1/(1+exp(-uh3));
uo1=y1*w(1,1)+y2*w(1,2)+y3*w(1,3)+1*bo1;
o(i)=1/(1+exp(-uo1));
E=E+0.5*(t(i)-o(i)).^2;
deltao1=(t(i)-o(i))*o(i)*(1-o(i));
w(1,1)=w(1,1)+eta*deltao1*y1;
w(1,2)=w(1,2)+eta*deltao1*y2;
w(1,3)=w(1,3)+eta*deltao1*y3;
bo1=bo1+eta*deltao1*1;
deltah1=y1*(1-y1)*(deltao1*w(1,1));
deltah2=y2*(1-y2)*(deltao1*w(1,2));
deltah3=y3*(1-y3)*(deltao1*w(1,3));
% input weight updation
v(1,1)=v(1,1)+eta*deltah1*x1(i);
v(1,2)=v(1,2)+eta*deltah1*x2(i);
v(2,1)=v(2,1)+eta*deltah2*x1(i);
v(2,2)=v(2,2)+eta*deltah2*x2(i);
v(3,1)=v(3,1)+eta*deltah3*x1(i);
v(3,2)=v(3,2)+eta*deltah3*x2(i);
bh1=bh1+eta*deltah1*1;
bh2=bh2+eta*deltah2*1;
bh3=bh3+eta*deltah3*1;
end
plot(N,E);
hold on;
E=0;
end