fmincon does not respect MaxIter

7 次查看(过去 30 天)
Hello,
I do not understand why fmincon does not respect the maximum number of iteration I specify and does whatever it
l;ikes to do. My cod is very long to show you but I show the main part which I believe is enough:
Max_iter=solver{2};
par0=lb+(ub-lb).*rand(1,dim);
options=optimoptions('fmincon','MaxFunEvals',realmax,'MaxIterations',Max_iter,'OutputFcn',@(x,A,state)myoutput_fmincon_Spline(x,A,state));
problem = createOptimProblem('fmincon','objective',cost,'x0',par0,'lb',lb,'ub',ub,'options',options);
ms=MultiStart('UseParallel',UseParallel);
myCluster=parcluster('local');NumWorkers=myCluster.NumWorkers;
[EstimatedNoise_par, f_best]=run(ms,problem,NumWorkers);
I try Max_tier = 1 and I expect the code to stop fast but fminbcon ignore it.
Any idea?
Thanks in advance,
Babak
  8 个评论
Mohammad Shojaei Arani
Hi Torsten,
You know, I ma making a MATLAB package now. If it was for my personal use then I would not bother you. I need to publish this package. The package also has a tutorial. It is not really nice to write in the tutorial "stop it whenever you see that the solution does not improve". Furthermore, in my package a user can choose not to see the results in the command window. So, I AM SEEKING A WAY TO STOP THE CODE WITHOUT PRESSING THE Ctrl+C
Walter Roberson
Walter Roberson 2023-11-18
outputfcn returns a value. That value can directly signal stop (that is, it is a fundamental part of the design, easily done, not something obscure)
So your outputfcn could evaluate the solution at hand and somehow decide that it is good enough.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2023-11-18
编辑:Matt J 2023-11-18
Now you see that from iteration 26 the solution is really good with 4-5 digits of accuracy, so whay TolX=0.01 fails?
Remember that MultiStart is an outer function deploying many instances of fmincon. Each instance of fmincon has its own inner iteration sequence. The values you've set using optimoptions (e.g.TolX, MaxIter) are used by each instance of fmincon to decide when its inner iteration sequence will stop. They do not control the outer level deployments of MultiStart.
If you want to define your own stopping criterion for the outer sequence of deployments, you must define a separate OuputFcn for that and pass it to MultiStart directly, e.g.,
ms=MultiStart('UseParallel',UseParallel,'OutputFcn', @stopMultiStart);
See here, for an example:
  3 个评论
Matt J
Matt J 2023-11-19
The same remarks apply. You are passing in stopping criteria that govern the inner iterations of fmincon, but not the outer iterations of GlobalSearch.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Global or Multiple Starting Point Search 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by