clear;
% Read input file store in one array:
myfid=fopen('c:\windows\desktop\data5.txt','r');
A=fscanf(myfid,'%f');
fclose(myfid);
% initialize inputs:
l0in=[0 0 0 0];
% initialize weights:
w1=rand(5,4);
w2=rand(3,5);
w3=rand(1,3);
b1=rand(5,1);
b2=rand(3,1);
b3=rand(1);
alpha=0.3;
for mainloop=1:1000
%%%%%%%%%%%% One training set loop %%%%%%%%%%%%%%
for k=1:length(A)-1
% One forward propagation:
%layer0 (delay lines)
l0in(4)=l0in(3);
l0in(3)=l0in(2);
l0in(2)=l0in(1);
l0in(1)=A(k);
l0out=l0in';
%layer1 (5 cells)
net1=w1*l0out + b1;
l1out=1./(1+exp(-net1)) ; % logsigmoid(net1[x])
%layer2 (3 cells)
net2=w2*l1out + b2;
l2out=1./(1+exp(-net2)) ; % logsigmoid(net2[x])
%layer3 (1 cell- linear)
net3=w3*l2out + b3;
l3out=net3;
% One backward propagation:
s3=-2*1*(A(k+1)-l3out);
s2=diag((1-l2out).*l2out)*w3'*s3;
s1=diag((1-l1out).*l1out)*w2'*s2;
% Adjust the weights and biases:
w3=w3-alpha*s3*l2out'; % 1 cell
b3=b3-alpha*s3;
w2=w2-alpha*s2*l1out'; % 3 cells
b2=b2-alpha*s2;
w1=w1-alpha*s1*l0out'; % 5 cells
b1=b1-alpha*s1;
%%%%%%%%%%%% end one training set %%%%%%%%%%%%%%
end
% Find the MSE, after training
l0in=[0 0 0 0];
for k=1:length(A)-1
%layer0 (delay lines)
l0in(4)=l0in(3);
l0in(3)=l0in(2);
l0in(2)=l0in(1);
l0in(1)=A(k);
l0out=l0in';
%layer1 (5 cells)
net1=w1*l0out + b1;
l1out=1./(1+exp(-net1)) ; % logsigmoid(net1[x])
%layer2 (3 cells)
net2=w2*l1out + b2;
l2out=1./(1+exp(-net2)) ; % logsigmoid(net2[x])
%layer3 (1 cell - linear)
net3=w3*l2out + b3;
l3out=net3;
%Error
error(k)=A(k+1)-l3out;
end
% Mean square error
mse(mainloop)=mean(error.*error);
disp(mainloop);
end
               (
geocities.com/vienna/7079)                   (
geocities.com/vienna)