4

I'm trying to do a fairly simple optimization, but I keep getting the error 'Singular matrix C in LSQ subproblem'. I've tried to search the internet, however I couldn't find anything about why this occurs or how I could solve it.

The following code for some reason always returns the same error regardless of the fact that (as far as I understand) the constraint is always satisfied:

cons = ({'type': 'eq', 'fun': lambda x: 0})

res = scipy.optimize.minimize(
    cost_func,
    v_init,
    bounds=bounds,
    constraints=cons,
    options={'maxiter': 10, 'disp': True},
)

where the bounds are set such that every off-diagonal element must fall between 0 and 1 and every on-diagonal element must be 0 and v_init is a flattened matrix. When I remove the constraint, the optimization converges without any errors.

The cost function is quite sophisticated. It returns the total intraclass distance - interclass distance given a dissimilarity matrix calculated using the parameters v_init.

Can anyone enlighten me?

user2817219
  • 141
  • 1
  • 4
  • Could you please pose your cost function? – Alex R. Nov 23 '16 at 19:37
  • The cost function is quite sophisticated. It returns the total intraclass distance - interclass distance given a dissimilarity matrix calculated using the parameters v_init. – user2817219 Nov 24 '16 at 10:46
  • Unfortunately (1) the details matter and (2) diagnosing the problem likely will come down to investigating details of the cost function, the constraint, the data, and the code itself. "Enlightenment" therefore appears to require a full education in optimization, which is not something we can undertake here. – whuber Nov 24 '16 at 14:50
  • 1
    The reason was that constraints have to be continuous. – user2817219 Nov 28 '16 at 14:08
  • Isn't `lambda x: 0` continuous? – endolith Aug 29 '17 at 19:37

0 Answers0