%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
load data
M1=20;
epo=15;
A=4;
B=18;
B2=B/2+1
N=500;
M=(A+1)*(B+1);
for a0=1:A+1;
for b0=1:B+1;
i=(B+1)*(a0-1)+b0;
b_init(i)=((b0-B2)/10)/(2^(-A)); a_init(i)=1/(2^(-A));
c_init(i)=(20-A)/2;
end
end
w0=ones(1,M);
for i=1:N
for j=1:M
t=x(i);
t= a_init(j)*t-b_init(j);
%P0(i,j)= (cos(1.75*t)*exp(-t*t/2))/2^c_init(j);
P0(i,j)= ((1-t*t)*exp(-t*t/2))/2^c_init(j);
end
end
%calculation of output of network
for i=1:N
u=0;
for j=1:M
u=u+w0(j)*P0(i,j);%w0?aè¨?μ
end
y0(i)= u;% y(p)= u=??W(j)*phi(p,j)= ??W(j)* |μj(t)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:M
W(:,k)=P0(:,k);
end
for k=2:M
u=0;
for i=1:k-1
aik(i)=(P0(:,k)'*W(:,i))/(W(:,i)'*W(:,i));
u=u+aik(i) *W(:,i);
end
W(:,k)=P0(:,k)-u;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:M
g(i)= (W(:,i)'*d')/( W(:,i)'* W(:,i));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u=0;
for i=1:M
u=u+g(i)*(W(:,i)'*W(:,i));
end
DD=u;
for i=1:M
Erro(i)=(g(i)^2)*(W(:,i)'*W(:,i))/DD;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
k=1;
while(k<=M1)
u=1;
for i=2:M
if abs(Erro(u))
u=i
else u=u
end
end
I(k)=u;
Erro(u)=0
k=k+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:M1
u=I(k);
a(k)=a_init(u);
b(k)=b_init(u);
c(k)=c_init(u);
w1(k)=w0(u);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
epoch=1;
error=0.1;
err=0.0001;
lin=0.5;
while (error>=err & epoch<=epo)
for i=1:N
for j=1:M1
t=x(i);
t= a(j)*t-b(j);
%P1(i,j)= (cos(1.75*t)*exp(-t*t/2))/2^c(j);
P1(i,j)= ((1-t*t)*exp(-t*t/2))/2^c(j);
end
end
%calculation of output of network
for i=1:N
u=0;
for j=1:M1
u=u+w1(j)*P1(i,j);
end
y1(i)= u;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u=0;
for i=1:N
u=u+(d(i)-y1(i))^2;
end
u=u/2;%u=1/2??(d-p)^2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if u>error
lin=lin*0.8;
else
lin=lin*1.2;
end
error=u; %error=u=1/2??(d-p)^2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:M1
u=0;
for i=1:N
u=u+(d(i)-y1(i))*P1(i,j);
end
EW(j)=-u;
end
if epoch==1
SW=-EW;
w1_=w1;
else
SW=-EW+((EW*EW')*SW_)/(EW_*EW_');
end
EW_=EW;
SW_=SW;
w1=w1_+SW*lin;
w1_=w1;
%number of epoch increase by 1
epoch=epoch+1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,1,1);plot(x,d);
subplot(2,1,2);plot(x,y1);