where do u i place the code netc = closeloop(neto); netc = train(netc,X,Xoi,Aoi); in the code elow to avoid error
조회 수: 1 (최근 30일)
이전 댓글 표시
Thanks greg for the comments on my earlier question on this matter. I have presented it clearer.
The question is
1. where do i place
netc = closeloop(neto); netc = train(netc,X,Xoi,Aoi);
in order to train closeloop using weights from open-loop. i dont know exactly where to place it the script.
This is the error:
Error using network/train (line 340) Inputs and targets have different numbers of samples.
Error in ab (line 100) (% ab is the matlab script name) netc = train(netc,x,xi,ai)
2. I dont really understand how to go about your third suggestion but i am working on a time series with 68 data points for both input(normtrip) and output(normw) values or is that what i have described in 1.
3. The script is shown below once again: % X and T input and input series and output series variables respectively
X = tonndata(normtrip,false,false);
T = tonndata(normw,false,false);
% training function
trainFcn = 'trainlm';
% Creating narx network
inputDelays = 1:1; feedbackDelays = 1:1; hiddenLayerSize = 10; net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize,'open',trainFcn);
% Input and Feedback Pre/Post-Processing Functions
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.inputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% Prepare the Data for Training and Simulation
[x,xi,ai,t] = preparets(net,X,{},T);
% Setup Division of Data for Training, Validation, Testing.
net.divideFcn = 'dividerand'; % Divide data randomly net.divideMode = 'time'; % Divide up every sample net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
% mse is chosen as performance function
net.performFcn = 'mse'; % Mean Squared Error
% Plot Functions.
net.plotFcns = {'plotperform','plottrainstate', 'ploterrhist', ... 'plotregression', 'plotresponse', 'ploterrcorr', 'plotinerrcorr'};
% initializing weights
rng('default')
% Train the Network
[net,tr] = train(net,x,t,xi,ai)
% Test the Network
y = net(x,xi,ai);
e = gsubtract(t,y);
performance = perform(net,t,y)
% a plot of predicted series y and target(observed)series
B=cell2mat(y);
A=cell2mat(t);
x=(1:1:67);
figure plot(x,A,x,B)
% Recalculate Training, Validation and Test Performance
trainTargets = gmultiply(t,tr.trainMask);
valTargets = gmultiply(t,tr.valMask);
testTargets = gmultiply(t,tr.testMask);
trainPerformance = perform(net,trainTargets,y);
valPerformance = perform(net,valTargets,y);
testPerformance = perform(net,testTargets,y);
% View the Network
view(net);
% Closed Loop Network
netc = closeloop(net);
netc.name = [net.name ' - Closed Loop'];
view(netc);
[xc,xic,aic,tc] = preparets(netc,X,{},T);
netc = train(netc,x,xi,ai); (% line 100 where the error occurs where exactly shoult it be placed )
yc = netc(xc,xic,aic);
closedLoopPerformance = perform(net,tc,yc);
% Multi-step Prediction, all but 5 timesteps of the input series and output series are used to simulate the network in open loop.
numTimesteps = size(x,2);
knownOutputTimesteps = 1:(numTimesteps-5);
predictOutputTimesteps = (numTimesteps-4):numTimesteps;
X1 = X(:,knownOutputTimesteps);
T1 = T(:,knownOutputTimesteps);
[x1,xio,aio] = preparets(net,X1,{},T1);
[y1,xfo,afo] = net(x1,xio,aio);
% The network and its final states are converted to closed-loop form to make five predictions with only the five inputs provided.
x2 = X(1,predictOutputTimesteps);
[netc,xic,aic] = closeloop(net,xfo,afo);
[y2,xfc,afc] = netc(x2,xic,aic);
multiStepPerformance = perform(net,T(1,predictOutputTimesteps),y2)
% Step-Ahead Prediction Network
nets = removedelay(net);
nets.name = [net.name ' - Predict One Step Ahead'];
view(nets)
[xs,xis,ais,ts] = preparets(nets,X,{},T);
ys = nets(xs,xis,ais);
stepAheadPerformance = perform(nets,ts,ys)
% Changing the (false) values to (true) to enable the following code blocks.
if (false)
genFunction(net,'myNeuralNetworkFunction'); y = myNeuralNetworkFunction(x,xi,ai); end if (false)
genFunction(net,'myNeuralNetworkFunction','MatrixOnly','yes');
x1 = cell2mat(x(1,:));
x2 = cell2mat(x(2,:));
xi1 = cell2mat(xi(1,:));
xi2 = cell2mat(xi(2,:));
y = myNeuralNetworkFunction(x1,x2,xi1,xi2);
end
if (false)
gensim(net);
end
% a plot of predicted series from closeloop and target(observed) series.
B=cell2mat(yc);
A=cell2mat(t);
x=(1:1:67);
figure plot(x,A,x,B)
Thank you for the suggestions.
I hope it is now clearer.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!