How can I troubleshoot cases in which the optimizer functions within Optimization Toolbox violate constraints/bounds or hang during the optimization?

1 view (last 30 days)
I would like to be able to troubleshoot cases in which the optimizer functions within the Optimization Toolbox violate constraints/bounds or hang during the optimization.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Oct 2010
The following might be helpful for troubleshooting cases related to any optimization function that violates bounds/constraints:
1. Add a buffer to the constraints: If the optimizer violates the bounds, you can add some buffer to the bounds that are violated. For example, if the lower bound "lb" is violated, you would replace "lb" to be "lb_original + tolerance". Or, if "lb(3)" is violated, you can perturb just that component "lb(3) = lb_orignal(3) + tolerance". For the upper bounds, use "ub = ub_orig - tolerance".
You can do the same with constraints, but violation of bounds is more likely to cause the objective to be undefined than violation of constraints.
2. Check for randomness in the objective function: The optimizers in the Optimization Toolbox require the objective function to be totally deterministic in nature. Make sure that your objective function does not have any randomness associated with it. For example, having a random number generator inside the objective function can cause FMINCON to give incorrect results or cause abnormal behavior. The optimizer requires that the objective be a function (in the mathematical sense): that is, multiple calls to "f(x)" with fixed "x" should always return the same result.
3. Check for complex numbers, NaN values, or Inf values in the objective function: If the objective returns a complex number, NaN, or Inf, then the optimizers might hang or run into the infeasible region. To continue with the optimization, you can put a IF statement in the objective function so that as soon as the function returns a complex number, NaN, or Inf, you receive a warning message and the function waits for a keypress to continue. Below is some sample code that performs this:
function y = myobjfun(x)
% your main code to calculate y goes here
if ((~isreal(y))| isnan(y) | (~isfinite(y)))
disp('problem found: Unwanted objective function found';
keyboard
end
At this point, you can actually check if the bounds or other constraints are violated or not. If they are violated by a small amount, then refer to the first suggestion.
If you are using the FMINSEARCH function, you can replace the value of "y" at this point to "Inf", but that will not work for the FMINCON or FMINUNC functions. This is due to the fact that this will introduce a discontinuity into the function, which is not acceptable.
Note, the suggestions above will not necessarily eliminate the issue, but can go a long way in resolving the issue to some extent.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!