for i in range(0, n):
cons.append({'type': 'ineq', 'fun': lambda x, i=i: np.dot(x.T, params[:, i])})
cons.append({'type': 'ineq', 'fun': lambda x, i=i: -np.dot(x.T, params[:, i])})
This code is strange. Are you sure that's what you mean? To judge from the documentation, that's going to result in constraints ∀i
, np.dot(x.T, params[:, i]) >= 0 & -np.dot(x.T, params[:, i]) >= 0
. I.e., np.dot(x.T, params[:, i]) == 0
, i.e., x
is orthogonal to every constraint plane, i.e., x == 0
.
You probably want some constants in those lambda
s, like you have in the subsequent set of constraints, which translate to ∀i
, 0.01 <= abs(x[i]) <= 1
.