store performance coefficient of different iterations in a vector

1 view (last 30 days)
Hi everyone,
I developped a code for function approximation using neuralnetworks. the perfoamnce of each iteration is estimated using a performation coefficient (nse).
I want to store every nse coefficint of each iteration in a vector.
nse1=0.1;
% ANN Model--------------------------------
while nse1 < 0.44;
net=feedforwardnet([5 20 10]);
net.divideParam.trainRatio=0.7;
net.divideParam.testRatio=0.15;
net.divideParam.valRatio=0.15;
net.trainParam.lr=0.001;
net.trainParam.min_grad=1e-20;
net.trainParam.goal=1e-3;
net.trainParam.epochs=1000;
net.trainParam.show=20;
net.trainParam.max_fail=1000;
net.trainFcn = 'trainlm';
net.trainParam.mu=0.01;
% init_net = init(net);
net=train(net,ANN_Inputs,ANN_Target);
net_output1=net(ANN_Inputs);
Obs=ANN_Target';
Sim=net_output1';
% R2 = calculateR2(Obs,Sim)
nse1 = NSE(Obs,Sim)
end

Accepted Answer

Rik
Rik on 14 Mar 2022
Edited: Rik on 14 Mar 2022
Following the standard strategy:
nse1_vector=NaN(1,1000);
nse1_vector(1)=0.1;
nse1_index=1;
% ANN Model--------------------------------
while nse1_vector(nse1_index) < 0.44;
net=feedforwardnet([5 20 10]);
net.divideParam.trainRatio=0.7;
net.divideParam.testRatio=0.15;
net.divideParam.valRatio=0.15;
net.trainParam.lr=0.001;
net.trainParam.min_grad=1e-20;
net.trainParam.goal=1e-3;
net.trainParam.epochs=1000;
net.trainParam.show=20;
net.trainParam.max_fail=1000;
net.trainFcn = 'trainlm';
net.trainParam.mu=0.01;
% init_net = init(net);
net=train(net,ANN_Inputs,ANN_Target);
net_output1=net(ANN_Inputs);
Obs=ANN_Target';
Sim=net_output1';
% R2 = calculateR2(Obs,Sim)
nse1_index=nse1_index+1;
nse1_vector(nse1_index) = NSE(Obs,Sim);
fprintf('nse (it %d) = %.1f\n',nse1_index,nse1_vector(nse1_index))
end
nse1_vector((nse1_index+1):end)=[];
You can probably move a lot of that code outside of the loop, but I don't know enough of your application to suggest what exactly. Code that does not depend on the previous iteration should not be in the loop itself.
  1 Comment
Mahmoud Zemzami
Mahmoud Zemzami on 15 Mar 2022
Thank you so much for your valuable help. It works perfectely.
Indeed, I moved the code inside the loop as you suggested.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!