load('input.mat'); Input_Parameter = tonndata(inputData(:,(1:3)),false,false);
Target_Parameter = tonndata(inputData(:,1),false,false);
inputSeries = Input_Parameter; targetSeries = Target_Parameter;
inputDelays = 1:4; feedbackDelays = 1:4; hiddenLayerSize = 10; net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
% Prepare the Data for Training and Simulation % The function PREPARETS prepares time series data % for a particular network, shifting time by the minimum % amount to fill input states and layer states. % Using PREPARETS allows you to keep your original % time series data unchanged, while easily customizing it % for networks with differing numbers of delays, with % open loop or closed loop feedback modes. [inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);
% Set up Division of Data for Training, Validation, Testing net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
% Train the Network [net,tr] = train(net,inputs,targets,inputStates,layerStates);
% Test the Network outputs = net(inputs,inputStates,layerStates); errors = gsubtract(targets,outputs); performance = perform(net,targets,outputs);
% View the Network view(net) %———————————————— outputs = cell2mat(outputs); N=length(outputs); figure(1), hold on plot( 1:N, outputs, 'LineWidth', 2) plot( 1:N, outputs, 'ro', 'LineWidth', 2) legend( ' TARGET ', ' OUTPUT ' ) title( ' NARXNET EXAMPLE ' ) %————————————————–
netc = closeloop(net); netc.name = [net.name ' – Closed Loop']; view(netc) [xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries); yc = netc(xc,xic,aic); perfc = perform(netc,tc,yc);
nets = removedelay(net); nets.name = [net.name ' – Predict One Step Ahead']; view(nets) [xs,xis,ais,ts] = preparets(nets,inputSeries,{},targetSeries); ys = nets(xs,xis,ais); earlyPredictPerformance = perform(nets,ts,ys);
ys = cell2mat(ys); M=length(ys); figure(1), hold on plot( 1:M, ys, 'LineWidth', 1) plot( 1:M, ys, 'ro', 'LineWidth', 1) legend( ' TARGET ', ' OUTPUT ' ) title( ' NARXNET EXAMPLE ' )
Best Answer