cvxpy/mosek improving the precision of the solution

234 Views Asked by At

Currently my objective function gives me a solution in the magnitude of about 1e-6. I think that gives me some precision problem.

What's the best practice to handle this kind of problems? It seems like I can multiply the obj function by 1e6 for example, but not sure if that's the best way. What kind of parameters can I set?

1

There are 1 best solutions below

0
Michal Adamaszek On BEST ANSWER

Impossible to say for sure but let me use this to post some general guidelines about numerical problems when using CVXPY+Mosek.

  • try to keep all coefficients in your problem within the same 7-8 orders of magnitude, so don't have 1e+7 in one place and 1e-6 in another
  • try to keep the norm of the objective close to 1 (in terms of orders of magnitude, that is avoid objectives such as 1e+7 or 1e-7
  • avoid (near-)linear dependencies
  • make sure the problem is not borderline feasible/infeasible or otherwise ill-posed.
  • rescale the problem to get better coefficients, for instance if you are designing a road between two towns, maybe meters or even kilometers are better units of length than nanometers.
  • remember that CVXPY dualizes continuous problems, so what Mosek gets is the dual of what you entered, therefore various coefficients appear in different places than expected. See https://themosekblog.blogspot.com/2020/10/cvxpy-116.html if necessary

Here are some more modeling hints:

https://docs.mosek.com/modeling-cookbook/practical.html

and here are some more specific implementation hints including interesting Mosek parameters

https://docs.mosek.com/latest/pythonapi/debugging-numerical.html

Here you can see how to set Mosek parameters and write data to files from CVXPY

https://docs.mosek.com/latest/faq/faq.html#cvxpy

If you fail to get things to work as expected you can always save the task file of the problem and send it to Mosek support with an explanation.