I need to minimize numerically an expression with constraints. The expression also includes a numerical integral (called 'PNoninteract'). The minimization apparently stops prematurely (I know roughly what the answer should be and I see it is incorrect), while producing error messages regarding having reached complex numbers (where it should be restricted to Reals by the constraints). I receive messages such as:
I'm currently using `Method->"RandomSearch"` because my previous attempts (with a simpler version of this problem) only worked with this method and produced similar error messages with all other methods (including the other stochastic methods).
Any idea how to resolve this? Thanks!
My code:
P = {29/61, 18/61, 10/61, 4/61};
K = 10;
M = 1;
Eth = -6;
Lmod = 40;
RealL = 18;
V = Array[v, 4];
U = Array[u, {4, 4}];
Q = Array[q, 6];
Q[[1]] = V[[1]]*U[[1, 1]];
Q[[2]] = V[[1]]*(U[[1, 2]] + U[[1, 3]] + U[[1, 4]]) +
V[[2]]*U[[2, 1]] + V[[3]]*U[[3, 1]] + V[[4]]*U[[4, 1]];
Q[[3]] = V[[2]]*U[[2, 2]];
Q[[4]] = V[[2]]*(U[[2, 3]] + U[[2, 4]]) + V[[3]]*U[[3, 2]] +
V[[4]]*U[[4, 2]];
Q[[5]] = V[[3]]*U[[3, 3]] + V[[4]]*U[[4, 4]];
Q[[6]] = V[[3]]*U[[3, 4]] + V[[4]]*U[[4, 3]];
EnergyVals = {-1, 0, -0.75, -0.25, 1, -1.25};
PNoninteract =
Probability[{x, y, z, w, c, d} . EnergyVals >=
Eth, {x, y, z, w, c, d} \[Distributed]
MultinomialDistribution[RealL, Q]];
allM = \!\(
\*UnderoverscriptBox[\(∑\), \(a =
1\), \(4\)]\(V[\([\)\(a\)\(]\)]*\(
\*UnderoverscriptBox[\(∑\), \(b = 1\), \(4\)]U[\([\)\(a,
b\)\(]\)]*\((K*
Log[U[\([\)\(a, b\)\(]\)]/P[\([\)\(b\)\(]\)]] +
Log[V[\([\)\(a\)\(]\)]/P[\([\)\(a\)\(]\)]])\)\)\)\) -
Log[1 - PNoninteract^M];
Energy = {{-1, 0, 0, 0}, {0, -0.75, -0.25, -0.25}, {0, -0.25,
1, -1.25}, {0, -0.25, -1.25,
1}};
Emean = \!\(
\*UnderoverscriptBox[\(∑\), \(a =
1\), \(4\)]\(V[\([\)\(a\)\(]\)] \(
\*UnderoverscriptBox[\(∑\), \(b = 1\), \(4\)]U[\([\)\(a,
b\)\(]\)]\ Energy[\([\)\(a,
b\)\(]\)]\)\)\);
vars = Flatten[{U, V}];
constraint1 =
Table[{0 <= vars[[i]] <= 1, vars[[i]] ∈ Reals}, {i, 1,
Length[vars]}];
constraint2 = Total[V] == 1;
constraint3 = Total[U[[1]]] == 1;
constraint4 = Total[U[[2]]] == 1;
constraint5 = Total[U[[3]]] == 1;
constraint6 = Total[U[[4]]] == 1;
constraint7 = Emean >= Eth/Lmod;
cons = {constraint1, constraint2, constraint3, constraint4,
constraint5, constraint6, constraint7} // Flatten;
SolK10M1 = NMinimize[{allM, cons}, vars, Method -> "RandomSearch"]
PNoninteract = Probability[{x, y, z, w, c, d} . EnergyVals >= Eth, {x, y, z, w, c, d} \[Distributed] MultinomialDistribution[RealL, Q]]
OK? $\endgroup$