필터 지우기
필터 지우기

Fmincon stuck within an iteration for a particular start point

조회 수: 13 (최근 30일)
Hari
Hari 2015년 8월 3일
댓글: Sean de Wolski 2016년 12월 13일
Hi,
I'm doing (nonlinear/non-convex) constrained optimization using SQP algorithm on a fairly small sized problem (average ~0.5 second to optimal solution in a 2 core i7 computer under no other load). I'm solving this problem across a large # of start points (and some parameterization) using parfor loop.
The algorithm runs fine for most part and I'm getting valid solutions.
Unfortunately for certain start point combinations (and parameterization) the algorithm is endlessly executing without doing a time-out.
I tried to understand why it is stuck and turned on certain options in fmincon/SQP using:
SQPoptions = optimoptions(@fmincon,'Algorithm','sqp','Display','iter-detailed','TolX',Tol(4),'TolFun',Tol(1),...
'GradObj','on', 'GradConstr','on','ObjectiveLimit',1e-20);
[sqpxstar, sqpfval, sqpmflag, sqpoutput] = fmincon(ObjFunGrad,[TempRw(NumOfParms+1:NumOfParms+...
(NumOfExpVar*CurrExpRunCnter))],LHSMatrixLinIneq{CurrExpRunCnter},...
RHSVectorLinIneq{CurrExpRunCnter},LHSMatrixLinEq{CurrExpRunCnter},RHSVectorLinEq{CurrExpRunCnter},...
FillUpAlgoDesBoundsLow,FillUpAlgoDesBoundsHigh,[],SQPoptions);
I'm not providing the objective function, constraints etc as they are very nasty expressions (dynamically generated using symbolic expression)
But here is the output for one of the start point combinations. It will display the Iteration 3 and nothing after that (even after waiting for 1 hour). Do note that the initial 3 iterations do not take more than a fraction of a second but after that it is endlessly processing with no seeming progress
Norm of First-order
Iter F-count f(x) Feasibility Steplength step optimality
0 1 4.113395e+19 0.000e+00 2.940e+19
User objective function returned Inf; trying a new point...
1 3 5.096751e+04 0.000e+00 7.000e-01 6.623e+01 2.058e+19
User objective function returned NaN; trying a new point...
2 5 8.540454e+03 0.000e+00 7.000e-01 2.213e+01 6.174e+18
User objective function returned NaN; trying a new point...
3 7 4.774538e+03 0.000e+00 7.000e-01 3.456e+02 3.519e+02
Stopping it by pressing control + break just spits out the message that
Operation terminated by user during computeSearchDirSQP (line 49)
In sqpLineSearch (line 281)
In fmincon (line 806)
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
What is the right way to debug this?
I'm ok with prematurely exiting if there is no progress after X amount of time and will just try the next start point in the par for loop. But failed to see any such option in fmincon?
Thanks
Hari
PS: Here is the final SQP options:
>> SQPoptions
SQPoptions =
fmincon options:
Options used by current Algorithm ('sqp'):
(Other available algorithms: 'active-set', 'interior-point', 'trust-region-reflective')
Set by user:
Algorithm: 'sqp'
Display: 'iter-detailed'
GradConstr: 'on'
GradObj: 'on'
ObjectiveLimit: 1.0000e-20
TolFun: 1.0000e-06
TolX: 1.0000e-04
Default:
DerivativeCheck: 'off'
Diagnostics: 'off'
DiffMaxChange: Inf
DiffMinChange: 0
FinDiffRelStep: 'sqrt(eps)'
FinDiffType: 'forward'
FunValCheck: 'off'
MaxFunEvals: '100*numberOfVariables'
MaxIter: 400
OutputFcn: []
PlotFcns: []
ScaleProblem: 'none'
TolCon: 1.0000e-06
TypicalX: 'ones(numberOfVariables,1)'
UseParallel: 0
Show options not used by current Algorithm ('sqp')

채택된 답변

Matt J
Matt J 2015년 8월 3일
편집: Matt J 2015년 8월 3일
What is the right way to debug this?
My suspicion is that fmincon is reaching a point x which, when fed to your objective function and/or constraints, results in a lot of calculations with NaNs in your "nasty expressions". Computations involving NaNs are very slow and bundling a million NaN operations into one big long expression could result in a particularly slow function evaluation. It's just one of the disadvantages of symbolically generated objectives/constraints.
To debug, my suggestion would be to do
>>dbstop if naninf
and rerun the code (without parfor). Use DBSTEP (or its equivalent in the debugger GUI) until you reach the point where the algorithm hangs. Then you can identify the particular point x which is causing your code to hang and study what your expressions are doing at that x.
  댓글 수: 5
Sean de Wolski
Sean de Wolski 2015년 8월 4일
You could use parfeval in the Parallel Computing Toolbox to "submit" a call or bunch of calls to fmincon. If enough time elapses (or if you get a positive exit flag(!)), then cancel the parfeval futures and keep going.
Hari
Hari 2015년 8월 5일
Hello Sean,
That seems like a very interesting approach. I will read up on parfeval and get back in case of questions
Thanks
Hari

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Tao Lu
Tao Lu 2016년 12월 13일
Hi, Hari:
Do you already solve the original problem? Since I also have the same problem when using fmincon with lots of initial guesses and conditions.
Thank you.
  댓글 수: 1
Sean de Wolski
Sean de Wolski 2016년 12월 13일
In recent releases of MATLAB there is a "Pause" button. I would encourage you to use it to stop fmincon in its tracks in debug mode so you can see what's going on.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by