lsqnonlin - output value at each iteration?

조회 수: 21 (최근 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에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by