0

I have a matrix A of size m x m

enter image description here

and while using scipy, I need to define the inequality constraint in python for items of this matrix that verifies:

enter image description here.

I managed to define the bounds between -1 and 1 :

enter image description here

in python as follows:

# -1 <= a[i][j] <= 1
bnds_a_s_t = [(-1,1) for _ in range(np.size(A))]

But I don't know how to define the inequality constraint. Should I use a for loop with 2 pointers and add them to a list of inequality constraints? In this case, what should I return from the inequality function? In the equations, M is a list of size m.

joni
  • 6,840
  • 2
  • 13
  • 20
LoveCode
  • 13
  • 3
  • Please provide a minimal reproducible example. Since scipy consists of many submodules, you have to be more specific, i.e. what method are you are trying to use? – joni Jun 10 '21 at 05:08
  • @joni I provided a minimal reproducible example in the answer below, thank you in advance for checking it when you have time. – LoveCode Jun 10 '21 at 18:06

1 Answers1

0

If you want to use it in a nonlinear programming you can use have a matrix that is constrained by construction, starting with an arbitrary matrix A, you can use, for instance

def constrained(A):
  return np.tanh(A - A.T);

The matrix a = A - A.T will ensure that a[t,s] + a[s,t] = 0 the tanh is such that tanh(-x) = -tanh(x), so the identity will be preserved for a = tanh(A - A.T), furthermore -1 <= tanh(x) <= 1. So constrained(A) gives what you need.

Bob
  • 13,867
  • 1
  • 5
  • 27
  • 1
    You see why you have to provide a minimum working example. I tried to guess what you wanted and I guessed wrong. What you must have is in your objective function implementation compute `a = np.reshape(a, (n,n)); a = np.tanh(A - np.transpose(A))` and then use a (that satisfy your constraints) to compute the objective value. – Bob Jun 10 '21 at 10:42