I've got a function g
which I'm minimizing over an array coeffs
subject to a list of constraints cons
.
If I use
n = 2
cons2 = [{'type': 'eq', 'fun': lambda cts: 1 - sabs(apNn(n,n,np.roll(cts, - 0 * 2**(n + 1))))},
{'type': 'eq', 'fun': lambda cts: 1 - sabs(apNn(n,n,np.roll(cts, - 1 * 2**(n + 1))))}]
ans = scipy.optimize.minimize(g, coeffs, constraints=cons2)
then everything works fine. (sabs
and apNn
are functions I've defined previously.).
However if I generate the constraints in a loop and use:
cons = []
for v in range(2):
cons.append({'type': 'eq', 'fun': lambda cts: 1 - sabs(apNn(n,n,np.roll(cts, - v * 2**(n + 1))))})
ans = scipy.optimize.minimize(g, coeffs, constraints=cons)
then the optimization fails with message Singular matrix C in LSQ subproblem
. Given that the for loop is generating exactly the same thing I can't see where this difference is coming from.