8.2 Addressing numerical issues¶
The suggestions in this section should help diagnose and solve issues with numerical instability, in particular UNKNOWN
solution status or solutions with large violations. Since numerically stable models tend to solve faster, following these hints can also dramatically shorten solution times.
We always recommend that issues of this kind are addressed by reformulating or rescaling the model, since it is the modeler who has the best insight into the structure of the problem and can fix the cause of the issue.
Some information about the numerical properties of the data can be obtained by dumping the problem to a file (see Sec. 8 (Debugging Tutorials)) and using the anapro
option of any of the command line tools.
8.2.1 Formulating problems¶
Scaling
Make sure that all the data in the problem are of comparable orders of magnitude. This applies especially to the linear constraint matrix. Use Sec. 8.1.1 (Input data) if necessary. For example a report such as
|A| nnz: 597023 min=1.17e-6 max=2.21e+5
means that the ratio of largest to smallest elements in A
is
Similarly, if the objective contains very different coefficients, say
then it is likely to lead to inaccuracies. The objective will be dominated by the contribution from
Removing huge bounds
Never use a very large number as replacement for
Avoiding linear dependencies
As much as possible try to avoid linear dependencies and near-linear dependencies in the model. See Example 8.3.
Avoiding ill-posedness
Avoid continuous models which are ill-posed: the solution space is degenerate, for example consists of a single point (technically, the Slater condition is not satisfied). In general, this refers to problems which are borderline between feasible and infeasible. See Example 8.1.
Scaling the expected solution
Try to formulate the problem in such a way that the expected solution (both primal and dual) is not very large. Consult the solution summary Sec. 8.1.2 (Solution summary) to check the objective values or solution norms.
8.2.2 Further suggestions¶
Here are other simple suggestions that can help locate the cause of the issues. They can also be used as hints for how to tune the optimizer if fixing the root causes of the issue is not possible.
Remove the objective and solve the feasibility problem. This can reveal issues with the objective.
Change the objective or change the objective sense from minimization to maximization (if applicable). If the two objective values are almost identical, this may indicate that the feasible set is very small, possibly degenerate.
Perturb the data, for instance bounds, very slightly, and compare the results.
For linear problems: solve the problem using a different optimizer by setting the parameter
MSK_IPAR_OPTIMIZER
and compare the results.Force the optimizer to solve the primal/dual versions of the problem by setting the parameter
MSK_IPAR_INTPNT_SOLVE_FORM
orMSK_IPAR_SIM_SOLVE_FORM
. MOSEK has a heuristic to decide whether to dualize, but for some problems the guess is wrong an explicit choice may give better results.Solve the problem without presolve or some of its parts by setting the parameter
MSK_IPAR_PRESOLVE_USE
, see Sec. 12.1 (Presolve).Use different numbers of threads (
MSK_IPAR_NUM_THREADS
) and compare the results. Very different results indicate numerical issues resulting from round-off errors.
If the problem was dumped to a file, experimenting with various parameters is facilitated with the MOSEK Command Line Tool or MOSEK Python Console Sec. 8.4 (Python Console).
8.2.3 Typical pitfalls¶
A toy example of this situation is the feasibility problem
whose only solution is
If the norm of the expected solution is very large it may lead to numerical issues or infeasibility. For example the problem
may be declared infeasible because the expected solution must satisfy
Consider the following problem:
If we add the equalities together we obtain:
which is infeasible for any
Next consider the problem
Now the MOSEK presolve will, for the sake of efficiency, fix variables (and constraints) that have tight bounds where tightness is controlled by the parameter MSK_DPAR_PRESOLVE_TOL_X
. Since the bounds
are tight, presolve will set MSK_DPAR_PRESOLVE_TOL_X
to say