lsqnonlin - output value at each iteration?

9 次查看(过去 30 天)
TSPQ
TSPQ 2011-7-21
评论: Sonia 2015-6-10
Using lsqnonlin, how do I output the value of each each iteration? It doesn't seem that the output arguments (x, resnorm, residual, exitflag, output, lambda, jacobian) contain this information.
Also, if I use opt = optimset('Display','iter-detailed'), I get the values: Iteration #, Func-count, Residual, First-Order Optimality, Lambda, and Norm of step. which don't actually tell me the value of each iteration.
  1 个评论
Sonia
Sonia 2015-6-10
I think you can simply add a "disp" command after definition of your objfun. Because what you pass to lsqnonlin is a vector, you can calculate your function value and eventually RMSE. Such as:
function objfun = objfun(prm)
(...define prm)
objfun = Tfield_obj-Tsim_obj;
lsqnonlin_value = sum(objfun.^2);
nData = size(Tfield_obj,1);
iter = iter+1
RMSE_iter(end+1) = sqrt(lsqnonlin_value/nData);
disp(['--- Current FunEval/Iteration completed. ObjFun value: ',num2str(lsqnonlin_value),'. RMSE: ',num2str(RMSE_iter(end)),' ---'])
end
I also wanted to know how the lsqnonlin is progressing in parameters update, so at each parameter update I requested it to output the current parameter combination (updated at each function evaluation/iteration):
function objfun = objfun(prm)
varParams(step).kfrost = prm(1); % kfrost
varParams(step).Porosity = prm(2); % Porosity
varParams(step).a = prm(3); % a
varParams(step).b = prm(4); % b
disp('----------- NEW PARAMETER GUESS -----------')
disp(['Running FunEval with new parameter guess: '...
'kfrost = ',num2str(varParams(step).kfrost),' [W/m/K], '...
'Porosity = ',num2str(varParams(step).Porosity),' [m3/m3], '...
'a = ',num2str(varParams(step).a),' [-], '...
'b = ',num2str(varParams(step).b),' [-].'])
(...define objfun)
end
What lsqnonlin displays during the iterative display are best result of all function evaluations within the given iteration.

请先登录,再进行评论。

回答(1 个)

Steve Grikschat
Steve Grikschat 2011-7-25
I'm not sure what you mean by "value of each iteration". The parameter values? The value of your system (F(x))?
Either way, look into OutputFcns, which lsqnonlin will call at each iteration. The information you're looking for is likely "x" or something in the optimValues structure.
See:
and

类别

Help CenterFile Exchange 中查找有关 Multiobjective Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by