An error due to output function
2 次查看(过去 30 天)
显示 更早的评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!