NARX neural network multistep prediction improvement

Hi, I'm trying to predict using NARX neural network. What I'm using the data are 3 inputs and 3 outputs. Actually, these data are not time varying. I'm just measured statically. So first I changed the data using con2seq command. And the detailed code is below. My problem is I'm using 2 types of data. First one is used for training and validation (data1.txt). Second one is used for actual test (data2.txt). Second data is experimental data. So I need to predict using this. The training and validation is very accurate, however, when I use the second data to test the neural network. the results are terrible. Though the test data exist in the training and validation data range. But there's no exact same data. I need to improve the accuracy of the test results. I attached the data files also. Please help me or give me some comments to solve this problems. Thank you.
clc;clear all;close all;tic
data1=load('data1.txt');
input=data1(:,4:6)';
target=data1(:,1:3)';
data2=load('data2.txt');
input2=data2(:,[6,5,4])';
target2=data2(:,1:3)';
y=con2seq(target);
u=con2seq(input);
y2=con2seq(target2);
u2=con2seq(input2);
%%traingdx
d1=1:2;
d2=1:2;
narx_net=narxnet(d1,d2,[10,10,10]);
narx_net.trainParam.min_grad=1e-10;
narx_net.trainFcn='trainlm';
[p,Pi,Ai,t]=preparets(narx_net,u,{},y);
for ii=1:30
narx_net=train(narx_net,p(:,1:11000),t(:,1:11000),Pi);
yp=sim(narx_net,p(:,1:11000),Pi);
e=cell2mat(yp)-cell2mat(t(:,1:11000));
ii
max(abs(e'))
yp2=sim(narx_net,p(:,11001:end),Pi);
e2=cell2mat(yp2)-cell2mat(t(:,11001:end));
max(abs(e2(:,max([d1 d2])+1:end)'))
if (max(abs(e'))<0.01)
if(max(abs(e2(:,max([d1 d2])+1:end)'))<0.01)
[p2,Pi2,Ai2,t2]=preparets(narx_net,u2,{},y2);
yp3=sim(narx_net,p2,Pi2);
e3=cell2mat(yp3)-cell2mat(t2);
max(abs(e3'))
if(max(abs(e3'))<0.5)
break
else
narx_net=init(narx_net);
end
else
narx_net=init(narx_net);
end
end
end
[p2,Pi2,Ai2,t2]=preparets(narx_net,u2,{},y2);
yp3=sim(narx_net,p2,Pi2);
e3=cell2mat(yp3)-cell2mat(t2);
toc
A1=cell2mat(yp);
A2=cell2mat(t(:,1:11000));
A3=cell2mat(yp2);
A4=cell2mat(t(:,11001:end));
A5=cell2mat(yp3);
A6=cell2mat(t2);
figure(1)
hold on
plot(A1(1,:),'or')
plot(A2(1,:),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training (Alpha)'
xlabel 'The number of data'
ylabel 'Target value'
figure(2)
hold on
plot(A1(2,:),'or')
plot(A2(2,:),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training (Beta)'
xlabel 'The number of data'
figure(3)
hold on
plot(A1(3,:),'or')
plot(A2(3,:),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training (Gamma)'
xlabel 'The number of data'
figure(4)
hold on
plot(A3(1,max([d1 d2])+1:end),'or')
plot(A4(1,max([d1 d2])+1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Alpha)'
xlabel 'The number of data'
figure(5)
hold on
plot(A3(2,max([d1 d2])+1:end),'or')
plot(A4(2,max([d1 d2])+1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Beta)'
xlabel 'The number of data'
figure(6)
hold on
plot(A3(3,max([d1 d2])+1:end),'or')
plot(A4(3,max([d1 d2])+1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Gamma)'
xlabel 'The number of data'
figure(7)
plot((e(1,:)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training error (Alpha)'
xlabel 'The number of data'
ylabel 'Error'
figure(8)
plot((e(2,:)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training error (Beta)'
xlabel 'The number of data'
ylabel 'Error'
figure(9)
plot((e(3,:)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Training error (Gamma)'
xlabel 'The number of data'
ylabel 'Error'
figure(10)
plot((e2(1,max([d1 d2])+1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Alpha)'
xlabel 'The number of data'
ylabel 'Error'
figure(11)
plot((e2(2,max([d1 d2])+1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Beta)'
xlabel 'The number of data'
ylabel 'Error'
figure(12)
plot((e2(3,max([d1 d2])+1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Gamma)'
xlabel 'The number of data'
ylabel 'Error'
figure(13)
% subplot(131)
plot((e3(1,1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Alpha) - Exp data'
xlabel 'The number of data'
ylabel 'Error'
figure(14)
% subplot(132)
plot((e3(2,1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Beta) - Exp data'
xlabel 'The number of data'
ylabel 'Error'
figure(15)
% subplot(133)
plot((e3(3,1:end)),'k')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction error (Gamma) - Exp data'
xlabel 'The number of data'
ylabel 'Error'
figure(16)
hold on
plot(A5(1,1:end),'or')
plot(A6(1,1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Alpha) - Exp data'
xlabel 'The number of data'
ylabel 'Target value'
figure(17)
hold on
plot(A5(2,1:end),'or')
plot(A6(2,1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Beta) - Exp data'
xlabel 'The number of data'
figure(18)
hold on
plot(A5(3,1:end),'or')
plot(A6(3,1:end),'sk')
legend('NN output', 'Target')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Prediction (Gamma) - Exp data'
xlabel 'The number of data'
error11=zeros(3,length(A5(1,:)));
% error11(1,:) = A5(1,2:8) - A6(1,2:8);
% error11(2,:) = A5(2,2:8) - A6(2,2:8);
% error11(3,:) = A5(3,2:8) - A6(3,2:8);
% error11(1,:) = A5(1,1:8) - A6(1,1:8);
% error11(2,:) = A5(2,1:8) - A6(2,1:8);
% error11(3,:) = A5(3,1:8) - A6(3,1:8);
% error11=zeros(3,69);
error11(1,:) = A5(1,:) - A6(1,:);
error11(2,:) = A5(2,:) - A6(2,:);
error11(3,:) = A5(3,:) - A6(3,:);
figure(19)
hold on
plot(error11(1,:),'-or')
plot(error11(2,:),'-sb')
plot(error11(3,:),'-^k')
grid on
legend('\alpha','\beta','\gamma')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Numerical error'
xlabel 'The number of data'
figure(20)
hold on
plot(error11(1,:)-mean(error11(1,:)),'-or')
plot(error11(2,:)-mean(error11(2,:)),'-sb')
plot(error11(3,:)-mean(error11(3,:)),'-^k')
grid on
legend('\alpha','\beta','\gamma')
set(gca,'FontName','Times new roman','FontSize',12,'FontWeight','Bold')
title 'Numerical error(Except mean)'
xlabel 'The number of data'
%max err
max_alp = max(abs(error11(1,:)))
max_bet = max(abs(error11(2,:)))
max_gam = max(abs(error11(3,:)))
%mean err
mean_alp = mean(abs(error11(1,:)))
mean_bet = mean(abs(error11(2,:)))
mean_gam = mean(abs(error11(3,:)))
save 'matlab2(current best results)'

Antworten (0)

Gefragt:

am 7 Nov. 2017

Bearbeitet:

am 13 Nov. 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!