store performance coefficient of different iterations in a vector

2 次查看(过去 30 天)
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

采纳的回答

Rik
Rik 2022-3-14
编辑:Rik 2022-3-14
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 个评论
Mahmoud Zemzami
Mahmoud Zemzami 2022-3-15
Thank you so much for your valuable help. It works perfectely.
Indeed, I moved the code inside the loop as you suggested.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by