1
$\begingroup$

I want to minimize (1/4b)[(Π1-s)'K(Π1-s)+(Π'1-t)'K(Π'1-t)] - tr(KΠ) with respect to Π. Can someone show me how I can do this in Mathematica?

Π is an nxn matrix and 1 denotes the all ones' vector. Also s and t are vectors of dimension n and b is a fixed scalar. So the only quantity that varies is Π, and for that matrix, we have the constraint that all the entries sum up to 1.

I'm just wondering if anyone could show me sample code I could use as a template to work through this.

$\endgroup$

1 Answer 1

1
$\begingroup$

Assuming that $(\cdot)'$ is transposition and considering a convenient restriction to avoid unlimited solutions,

n = 4
b = 2;
SeedRandom[1]
PP = Array[a, {n, n}];
KK = RandomReal[{-1, 1}, {n, n}] + 4 b IdentityMatrix[n];
s = Partition[RandomReal[{-1, 1}, n], 1];
t = Partition[RandomReal[{-1, 1}, n], 1];
ones = Partition[Table[1, n], 1];
f = (1/4/b) (Transpose[PP.ones - s].KK.(PP.ones - s) + Transpose[Transpose[PP].ones - t].KK.(Transpose[PP].ones - t)) - Tr[KK.PP];
vars = Variables[PP];
restr = Total[vars] <= 1;
opt = Join[Flatten[f], {restr}];
NMinimize[opt, vars]
$\endgroup$
4
  • $\begingroup$ Thank you! And a related question -- when I set restr = vars.Table[1,n*n] <= 1...I get that NMinimize fails to converge. Also, how do I add the constraint that every element of PP is nonnegative? $\endgroup$
    – Kashif
    Mar 11, 2020 at 13:15
  • $\begingroup$ The restrictions should model the problem you are handling. Depending on the nature of KK (positive definite, negative definite, indefinite, etc. ) your linear restriction can work. Any way, the modeling should reflect the real problem to optimize. $\endgroup$
    – Cesareo
    Mar 11, 2020 at 13:48
  • $\begingroup$ How can I set a restriction on KK to be PSD? $\endgroup$
    – Kashif
    Mar 11, 2020 at 13:51
  • 1
    $\begingroup$ I have introduced some changes in the script to assure a sufficient positiveness on KK in order to have finite results under the assumption of linear restrictions. $\endgroup$
    – Cesareo
    Mar 11, 2020 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.