Fmincon Numerical Issue: Intermediate Iterations Violate Implicit Boundaries

5 views (last 30 days)
Hi All,
I am having a numerical issue on Fmincon function in Matlab. My optimization problem is an nonlinear programming problem. The problem is this (I try to convert my problem into a simplified version so that you could understand what I am talking about :)
Say I want to optimize the problem with the cost function J = integral (x(t)-xref)^2dt (x is my optimization variables and basically it is just a plain vanilla reference tracking problem) There is no linear constraint for x, that is, x could be anything… There is nonlinear constraint. This is defined as follows:
a = f(x), where f is a nonlinear function
b= g(x), where g is a nonlinear function
c = b-constant, where c is the inequality nonlinear constraint (I do not have equality nonlinear constraint ceq, so ceq = [])
My problem was that to get inequality nonlinear constraint c I had to calculate the intermediate variables a and b. But there was some parts in function f and g such that it is not feasible to all the intermediate value , say sqrt(x), which is not feasible for negative x (x is my optimization variables). Because of this, when I used Fmincon function to optimize my problem, I always got the error (I turned on the option “FunValCheck”):
Error using optimfcnchk/checkfun (line 330)
User function ‘nonlinear_constraint’ returned NaN when evaluated;
FMINCON cannot continue.
Error in evalObjAndConstr (line 43)
Error in sqpLineSearch (line 291)
I suppose Matlab Fmincon function would give most feasible candidate values during intermediate iteration . There might be some infeasible value but it is supposed to be “dragged” back to feasible region in a few iterations. But in my case, I got infeasible values for optimization variables during intermediate iteration and then I got infinity error in the nonlinear constraint function and the program stopped due to the infinity error. Why is it? Is it because the Fmincon function is not good at my case? Should I try to use some other solvers such as, SNOPT? I do want to know what I could do to solve this issue using Fmincon. What should I do to make sure there would not have such error?
What I did to try to prevent this error is to add the following code to guarantee that during intermediate iterations x is non-negative:
if x <0
x = 0;
end
Although it turned out to be useless, I have also tried the tricks in nonlinear constraints such as the following
if x<0
c = 1; % c is the nonlinear inequality constraint in Fmincon
end
I did have read through and tried the tricks given the mathworks' websites on "Writing Constraints" and "When the Solver Fails". But it did not work. The algorithms I have used are "spq" and "interior-point" . They are supposed to meet the constraints during intermediate iterations.
Could anyone help me out at this point? I have been stuck here for several months. I really appreciate it!
Best wishes,
Ji

Answers (1)

Alan Weiss
Alan Weiss on 4 Aug 2014
At the initial point x0 are both your objective function and nonlinear constraint function real and finite? Do their derivatives exist at the initial point? If so, I suggest that you turn off the FunValCheck option and try again using the interior-point algorithm.
If the objective function, nonlinear constraint function, or any of their derivatives do not exist as finite real quantities at the initial point, then fmincon cannot continue. But, usually, once fmincon starts, it is robust enough to be able to continue past occasional function evaluation failures. In particular, I would not include that x < 0 change, but just let the function be NaN or coomplex, and fmincon will learn to avoid that point.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 6 Aug 2014
There is nothing that you can do to ensure the path that fmincon takes does not ever step outside your nonlinear constraint region. And if you use "tricks" like resetting c when x < 0, then you only confuse fmincon into thinking that a point where x < 0 is OK.
If you are certain that there are feasible points, then I suggest that you stick with the interior-point algorithm and try different initial points (x0). You can also try playing with some of the interior-point tuning options, such as InitBarrierParam, InitTrustRegionRadius, and ScaleProblem.
You can also set some other tolerances such as TolCon and TolFun to smaller-than-default values, perhaps 1e-12.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Ji
Ji on 6 Aug 2014
Hi Alan,
Thanks so much for your answer! While I once tried much smaller tolerance, I have never tried options like InitBarrierParam, InitTrustRegionRadius, and ScaleProblem. Your point is very well taken and I will try different initial points and these options to see if I could make some progress. I really appreciate your feedback!
Best wishes, Ji

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!