0

I am trying to minimize the function || Cx - d ||_2^2 with constraints Ax <= b. Some information about their sizes is as such:

* C is a (138, 22) matrix
* d is a (138,) vector
* A is a (138, 22) matrix
* b is a (138, ) vector of zeros

So I have 138 equation and 22 free variables that I'd like to optimize. I am currently coding this in Python and am using the transpose C.T*C to form a square matrix. The entire code looks like this

C = matrix(np.matmul(w, b).astype('double'))
b = matrix(np.matmul(w, np.log(dwi)).astype('double').reshape(-1))

P = C.T * C
q = -C.T * b
G = matrix(-constraints)
h = matrix(np.zeros(G.size[0]))
dt = np.array(solvers.qp(P, q, G, h, dims)['x']).reshape(-1)

where np.matmul(w, b) is C and np.matmul(w, np.log(dwi)) is d. Variables P and q are C and b multiplied by the transpose C.T to form a square multiplier matrix and constant vector, respectively. This works perfectly and I can find a solution.

I'd like to know whether this my approach makes mathematical sense. From my limited knowledge of linear algebra I know that a square matrix produces a unique solution, but is there is a way to run the same this to produce an overdetermined solution? I tried this but solver.qp said input Q needs to be a square matrix.

We can also parse in a dims argument to solver.qp, which I tried, but received the error:

use of function valued P, G, A requires a user-provided kktsolver.

How do I correctly setup dims?

Thanks a lot for any help. I'll try to clarify any questions as best as I can.

Jeff Y
  • 2,437
  • 1
  • 11
  • 18
  • It's hard to follow your question (unknown variables; mentioning of np.log and other stuff without any reason behind; arbitrary change between view like A<=b vs. constraints <= zeroMat). Just some remarks: (1) The basic construction looks good, except for (2) q is wrong as b is your constraint-vector, but q is constructed for the objective. Whatever you observed as `this works perfectly` must be wrong (or your treatment above is wrong). (3) Yes, it mathematically makes sense and an overdetermined system still has a least-squares solution. (4) cvxpy would allow to model this within a few lines. – sascha Aug 31 '19 at 00:27
  • So the question is: what exactly did go wrong? The above construction looks good and P will always be square (which is Q in qp-standardform). No need for the solver to complain. It's unclear to me, what the problem is without seeing working code and / or stack-traces. If you mention `Q`, it's unclear which `Q` you mean. So: try to provide details (if sticking with cvxopt after all; i **highly** recommend using cvxpy: more clean (mathematical) modelling, automatic rewriting/standardization + proof of convexity, interfacing more solvers). – sascha Aug 31 '19 at 00:29
  • Hi @sascha, After further reading on linear algebra, I now understand square matrices form a unique solution. I originally posted this question due to my lack of understanding of linear algebra, but reading up and consulting some mathematicians helped. I'll take your suggestion and move over to cvxpy instead - it looks good to me. – The Jaeger Aug 31 '19 at 02:04

0 Answers0