Training a network with multiple time series of a particular event (NARX)
이전 댓글 표시
I am fairly new to neural networks and matlab coding so please bear with me. I am trying to train a neural network to predict the outcomes of a SDOF spring, mass and damper simulation time series with the data coming from another simulation package. I would be really like to be able to feed in several individual examples of a test while chaning verious parameters e.g spring rate, mass and damping.
I have successfully been able to cobble together some code which allows me to go from csv files and feed them into the network and get results however, I have been trying to do this for "n" samples and I can't quite make it work. The dream would be to have a for loop over "n" samples and then train the network and run an unseen scenario. I have ran into the example here: https://uk.mathworks.com/help/deeplearning/ug/multiple-sequences-with-dynamic-neural-networks.html;jsessionid=068d9effcfb971932f62560a9690
When trying to impliment that example I ran into dimension errors which I didn't understand. Any help would be seriously appreciated as I am a total novice
I have pasted my working rev1 code below:
%The nonlinear autoregressive network with exogenous inputs
%used for prediction
%Future Development this would be a for loop over several timeseries
%samples to build a network
inputs1=importdata('1height.csv'); %upload data input for training and test
targets1=importdata('2height.csv'); %upload data target
% need to convert to format preparets understands
%Future Development this would represent the unknown variable test
inputs2=importdata('3height.csv'); %upload data (input) to test the model with new data samples
targets2=importdata('3height.csv'); % upload data (target)
aa1=inputs1';
aa2=targets1';
bb1=inputs2';
bb2=targets2';
out1=num2cell(aa1,1); %to convert aa1 to cell
out2=num2cell(bb1,1); %convert bb1 to cell
aaa2=num2cell(aa2,1); %to convert aa2 to cell
[x]=[out1];
[t]=[aaa2];
inputSeries = x;
targetSeries = t;
%create NARX network
inputDelays = 1:2;
feedbackDelays = 1:2;
hiddenLayerSize =10;
net=narxnet(inputDelays,feedbackDelays,hiddenLayerSize);
%training proportion setup
net.divideParam.trainRatio = 70/100;
net.divideParam.calRatio = 15/100;
net.divideParam.testRatio = 15/100;
%prepare the data for training and simulation using PREPARETS
[Xs,Xi,Ai,Ts] = preparets(net,x,{},t);
%train network
%Allows for training method to be changed
%trainbr for real tests will be used
trainFcn = 'trainlm';
net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
[net,tr]=train(net,Xs,Ts,Xi,Ai);
%test network
Y=net(Xs,Xi,Ai);
perf=mse(net,Ts,Y); %performance
E=gsubtract(Ts,Y); %error
%view network
view(net)
%plots(predictied using series-parallel NARXNN)
figure(1);
hold on;
plotperform(tr);
plotresponse(Ts,Y);
ploterrcorr(E);
plotinerrcorr(Xs,E);
%closed Loop network for multistep prediction
%The function CLOSELOOOP replaces feedback input with direct connection to
%output
netc=closeloop(net);
netc.name=[net.name '-Closed Loop'];
view(netc)
[Xs,Xi,Ai,Ts]=preparets(netc,x,{},t);
yc=netc(Xs,Xi,Ai);
%prediction using NARXNN in the case of new samples
figure(2);
hold on;
q=netc(out2,Xi,Ai); %q is predicted time series
w=cell2mat(q); %convert q from cell to numeric matrix
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 AI for Signals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!