понедельник, 27 февраля 2017 г.

Multistep Neural Network Prediction example

Multistep Neural Network Prediction

https://www.mathworks.com/help/nnet/ug/multistep-neural-network-prediction.html


% Multistep Neural Network Prediction

% Set Up in Open-Loop Mode

[X,T] = maglev_dataset;
net = narxnet(1:2,1:2,10);
[x,xi,ai,t] = preparets(net,X,{},T);
net = train(net,x,t,xi,ai);
y = net(x,xi,ai);
view(net)

% Multistep Closed-Loop Prediction From Initial Conditions

% Close loop
netc = closeloop(net);
view(netc);

[x,xi,ai,t] = preparets(netc,X,{},T);
yc = netc(x,xi,ai);

plot(1:3999, cell2mat(t), 'b', 1: 3999, cell2mat(yc),'r');

% Multistep Closed-Loop Prediction Following Known Sequence

x1 = x(1:20);
t1 = t(1:20);
x2 = x(21:40);

% The open-loop neural network is then simulated on this data.

[x,xi,ai,t] = preparets(net,x1,{},t1);
[y1,xf,af] = net(x,xi,ai);

%Now the final input and layer states returned by the network are converted to closed-loop form along with the network.
% The final input states xf and layer states af of the open-loop network become the initial input states xi and layer states ai of the closed-loop network.

[netc,xi,ai] = closeloop(net,xf,af);

%Typically use preparets to define initial input and layer states. 
% Since these have already been obtained from the end of the open-loop simulation,
% you do not need preparets to continue with the 20 step predictions of the closed-loop network

[y2,xf,af] = netc(x2,xi,ai);

% Note that you can set x2 to different sequences of inputs to test different scenarios for however many time steps you would like to make predictions.
% For example, to predict the magnetic levitation system's behavior if 10 random inputs are used:

x2 = num2cell(rand(1,10));
[y2,xf,af] = netc(x2,xi,ai);

% Following Closed-Loop Simulation with Open-Loop Simulation
[~,xi,ai] = openloop(netc,xf,af);

% Now you can define continuations of the external input and open-loop
% feedback, and simulate the open-loop network 

x3 = num2cell(rand(2,10));
y3 = net(x3,xi,ai);

Комментариев нет:

Отправить комментарий