0

I am trying to find an optimal solution on predefined np arrays and I need to use these arrays in constraints. I tried converting those arrays to cvxpy variables but it it says that cvxpy variables do not support assignment. Here is code for reference. Can somebody provide some tips?

N, d = xTr.shape y = yTr.flatten()

## Solution Start

# dummy code: example of establishing objective and constraints, and let the solver solve it.
si = np.random.randn(N)
w = Variable(d)
b = Variable(1)
objective = norm(w) + C * (sum(si))
constraints = []
for i in range(N):
    constraints += [
                    y[i]*(w * xTr[i] + b)+ si[i] >=1,
                    si[i] >= 0
                  ]
prob = Problem(Minimize(objective), constraints)
prob.solve()>
  • (1) Please post a complete script so that others can reproduce your error. (2) `si` is a constant, so the constraint `s[i] >= 0` does nothing; you should delete that constraint. – Akshay Agrawal Oct 06 '19 at 20:32
  • (See https://stackoverflow.com/help/minimal-reproducible-example for guidelines on writing reproducible examples.) – Akshay Agrawal Oct 06 '19 at 20:38

0 Answers0