Anda di halaman 1dari 2

%SURPRISE!!! ...

IT TURNS OUT THAT GOOD CL PREDICTION


%IS OBTAINABLE WITH JUST THE INPUT AND ZERO INITIAL
%CONDITIONS! THE ONLY DIFFERENCE IS THE TIME IT
%TAKES FOR THE ERROR TO %BECOME NEGLIGIBLE.

close all, clear all, clc


[ X, T ] = simplenarx_dataset;
neto = narxnet;
[ Xo, Xoi, Aoi, To ] = preparets( neto, X, {},T );
to = cell2mat(To);
varto = var(to,1) % 0.099154
[neto tro Yo Eo Xof Aof ] = train(neto,Xo,To,Xoi,Aoi );
view(neto)
NMSEo = mse(Eo)/varto % 2.2159e-08
netc = closeloop(neto);
T2 = T; T2(1:end) = {0};
[ Xc, Xci, Aci, Tc ] = preparets( netc, X, {}, T2 );
whos Xc Xci Aci Tc
% Aci 2x2 624 cell
% Tc 1x98 11760 cell
% Xc 1x98 11760 cell
% Xci 1x2 240 cell
[ Yc Xcf Acf ] = netc(Xc, Xci, Aci );
yc = cell2mat(Yc);
nerrc = (to-yc)/sqrt(varto);
figure;
subplot(211), hold on;
plot( to, 'b', 'linewidth', 3);
plot( yc, 'r--', 'linewidth',2);
legend( 'TARGET', 'ZERO-IC PREDICTIONS' )
xlabel( 'TIME' )
ylabel( 'OUTPUT' );
title(' ZERO INITIAL CONDITION PREDICTIONS')
subplot(212)
plot(nerrc, 'k' ,'linewidth',3);
legend( ' ZERO-IC PREDICTION ERROR ' )
xlabel( ' TIME ' )
ylabel('NORMALIZED ERROR');

%Original Code

clear all; clc;


[X, T]= simplenarx_dataset;
net=narxnet();
% set all weights and biases equal to zero
net = setwb(net,zeros(1,net.numWeightElements));
% Prepare the Data for Training and Simulation
[x,xi,ai,t] = preparets(net,X,{},T);
% Train the Network
[net,tr] = train(net,x,t,xi,ai);
% Test the Network
y = net(x,xi,ai);
performance = perform(net,t,y)
view(net)
%%
% Closed Loop Network
% Use this network to do multi-step prediction.
netc = closeloop(net);

%QUESTION IS IN THE FOLLOWING PART


% PEOPLE USUALLY DO THIS, HOWEVER, T IS NOT KNOWN A PRIORI
% [xc,xic,aic,tc] = preparets(netc,X,{},T);

% IS IT CORRECT TO DO AS FOLLOWS???
% multi-step prediction knowing input and initial condition of output. The
% input is taken as the one used for training the network.
% The output T2{1} = T{1}, T2{i>1}=0;
T2=T;
for i=2:length(T)
T2{i}=0;
end
[xc,xic,aic,tc] = preparets(netc,X,{},T2);
yc = netc(xc,xic,aic);

% PLOT FIGURE
%compare actual output vs. multi-step prediction
%knowing input and initial condition of output

figure();
plot(cell2mat(t),'-r','linewidth',2);
hold on;
plot(cell2mat(yc),'-.b','linewidth',1.5);
legend('actual output','multi-step prediction knowing input and initial condition
of output');
xlabel('time step')
ylabel('output');

Anda mungkin juga menyukai