Optimization Troubleshooting and Tips - MATLAB & Simulink (original) (raw)
Main Content
This table describes typical optimization problems and provides recommendations for handling them.
Problem | Recommendation |
---|---|
The solution found by fminbnd orfminsearch is not a_global_ minimum. A global minimum has the smallest objective function value among all points in the search space. | There is no guarantee that a solution is a global minimum unless your problem is continuous and has only one minimum. To search for a global minimum, start the optimization from multiple starting points (or intervals, in the case of fminbnd). |
It is impossible to evaluate the objective functionf(x) at some points x. Such points are called infeasible. | Modify your function to return a large positive value forf(x) at infeasible pointsx. |
The minimization routine appears to enter an infinite loop or returns a solution that is not a minimum (or not a zero, in the case of fzero). | Perhaps your objective function returns NaN or complex values. Solvers expect only real objective function values. Any other values can cause unexpected results. To determine whether there are NaN or complex values, set options = optimset('FunValCheck','on') and call the optimization function with options as an input argument. If an objective function returns aNaN or complex value, this setting causes the solver to throw an error. |
The solver takes a long time. | Most optimization problems benefit from good starting points. Try random starting points in a region that might be close to a solution, based on your problem characteristics. Sometimes you can solve a complicated problem using an evolutionary approach. First, solve problems with a smaller number of independent variables. Use solutions from these simpler problems as starting points for more complicated problems by using an appropriate mapping. Also, you can sometimes speed the solution by using simpler objective functions and less stringent stopping conditions in the initial stages of an optimization problem. |
It is unclear what the solver is doing. | To see what the solver is doing as it iterates: Monitor the iterations using a plot function such as@optimplotfval. Use optimset to set the PlotFcns option. See Optimization Solver Plot Functions.Set the Display option to display information at the command line. See Optimization Solver Iterative Display. |
fminsearch fails to reach a solution. | fminsearch can fail to reach a solution for various reasons. Poor scaling. If your problem is not adequately centered and scaled, the solver can fail to converge correctly. Try to have each coordinate give roughly the same effect on the objective function, and ensure that the scale of each coordinate near a possible solution is not too large or small. To do so, edit the objective function and add or multiply appropriate constants for each coordinate.Inappropriate stopping criteria. If the value you specify for TolFun or TolX is too small, fminsearch can fail to realize when it has reached a solution. If the value is too large,fminsearch can halt far from a solution.Poor initial point. Try startingfminsearch from various initial points.Insufficient iterations. If the solver runs out of iterations or gets stuck, try restartingfminsearch from its final point to reach a better solution. Sometimesfminsearch reaches a better solution when you increase the value of theMaxFunEvals andMaxIter options from their default of200*length(x0). |
Note
Optimization solvers apply to real-valued functions. Complex values cannot be optimized, except for a real-valued function of the complex values, such as the norm.