Thank you for posting your question here. This is a great opportunity to share a practical tip about using CVX effectively: avoid using quadratic forms like quad_form
and sum_square
whenever you can use norm
(without squaring it) instead. If you don’t quite understand this, read on; this problem is a perfect example of this lesson.
The standard solvers that CVX uses actually don’t handle quadratic forms very well. This may seem counterintuitive—after all, QP solvers have been around for a long time, right? But CVX doesn’t use QP solvers, it uses conic solvers. And translating quadratic forms to conic solvers can cause some scaling issues. Gurobi and MOSEK have dedicated support for quadratic objectives, but CVX cannot yet exploit that.
Therefore, it is always worthwhile to see if you can rewrite your problem to eliminate quadratics. In this case, this is not difficult. Your objective is equivalent to
\|C^{-1/2}(Ax-y)\|_2^2 + \lambda\|Dx\|_2^2 = \left\|\begin{bmatrix} C^{-1/2} ( A x - y ) \\ \sqrt{\lambda} D x \end{bmatrix} \right\|_2^2
Furthermore, since minimizing the norm is equivalent to minimizing the squared norm, you can drop the exponent. That means that you can use this objective in CVX:
norm( [ invL * ( A * x - y ) ; sqrt( lambda ) * D * x ] )
I think you will find that the scaling issues for this equivalent form are a lot better.
I suspect the variances you’re seeing when you rewrite the constraints in different ways are at least in part due to the quadratic form issue. You should certainly try both solvers to see which one works better for you (and, with the new version of CVX, try MOSEK and Gurobi too, of course.) Feel free to try boosting the precision (see the cvx_precision
command) to see if that helps as well.
As for the looping, there really is nothing else you can do. CVX does not have any sort of warm-start facility (not an easy thing to implement for such a general-purpose tool). To be honest, the primary goal of CVX is to get your models running as quickly as possible, not necessarily to solve them as quickly as possible.