An error due to output function
6 ビュー (過去 30 日間)
古いコメントを表示
Mohammad Shojaei Arani
2022 年 8 月 25 日
コメント済み: Mohammad Shojaei Arani
2022 年 8 月 25 日
Hellow,
I am getting an error message which I did not expect (I explain why). I am solving an optimization problem. When I use fmincon no error appears. But, when I use patternsearch I get an error message, so this is really unexpected. The following are relevant parts of my code:
This works and I get no error message:
options=optimoptions('fmincon','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M),'StepTolerance',10^(-12),'FunctionTolerance',10^(-12),'MaxFunEvals',10^8,'MaxIter',10^8);
fmincon(cost,par0,[],[],[],[],lb,ub,[],options);
But this does not work and I get an error message:
options=optimoptions('patternsearch','UseParallel',UseParallel,'Display','iter','OutputFcn',@(x,A,state)myoutput_Spline(x,A,state,dt,M));
patternsearch(cost,par0,[],[],[],[],lb,ub,[],options)
Error using myoutput_Spline
Too many output arguments.
My output function is:
function stop = myoutput_Spline(x,A,state,dt,M)
stop = false;
if isequal(state,'iter')
par=x;
par(1:M)=x(1:M)./dt;
par(M+1:end)=x(M+1:end)./sqrt(dt);
disp('Estimated parameters : ');
disp(num2str(par));
disp(['Approximate value of objective function (negative of sum of log-likelihoods) : ' num2str(A.fval)]);
end
end
I have no idea what the hell is this!!!
Thanks for your help
0 件のコメント
採用された回答
Walter Roberson
2022 年 8 月 25 日
Your output function must have the following calling syntax:
[stop,options,optchanged] = myfun(optimvalues,options,flag)
However, your outputfcn only has a single output.
The function definition line of the output function or plot function has the following form:
stop = outfun(x,optimValues,state)
You should be emitting all three outputs; fmincon should ignore the extra outputs.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!