Firstly, this seems like (from ContourPlot) a fairly straightforward maximization problem, why is FindMaximum with Newton’s method having problems?
Secondly, how can I get rid of the warnings?
Thirdly, if I can’t get rid of these warnings, how can I tell if the warning is meaningful, ie, maximization failed?
For instance, in the code below, FindMaximum with Newton’s method gives a warning, whereas the PrincipalAxis method doesn’t
o = 1/5 Log[E^(-(h/Sqrt[3]))/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
3/10 Log[E^(h/Sqrt[3])/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/5 Log[E^(-(h/Sqrt[3]) - Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(h/Sqrt[3] - Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(-Sqrt[3] h + Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(Sqrt[3] h + Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))];
(* -1 makes more contours towards maximum *)
contourFunc[n_, p_] := Function[{min, max},
range = max - min;
Table[Exp[p (x - 1)] x range + min, {x, 0, 1, 1/n}]
];
cf = contourFunc[10, -1];
ContourPlot @@ {o, {j, -1, 1}, {h, -1, 1}, Contours -> cf}
FindMaximum @@ {o, {{j, 0}, {h, 0}}, Method -> "Newton"}
FindMaximum @@ {o, {{j, 0}, {h, 0}}, Method -> "PrincipalAxis"}
Note, I thought that maybe gradient being 0 in direction of one of the components was the problem, but if I perturb the initial point I still get the same warning, here’s an example
o = 1/5 Log[E^(-(h/Sqrt[3]))/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/5 Log[E^(h/Sqrt[3])/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(-(h/Sqrt[3]) - Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
3/10 Log[E^(h/Sqrt[3] - Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(-Sqrt[3] h + Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))] +
1/10 Log[E^(Sqrt[3] h + Sqrt[2] j)/(
2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) +
E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) +
E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt[3] h + Sqrt[2] j))];
ContourPlot @@ {o, {j, -1, 1}, {h, -1, 1}}
FindMaximum @@ {o, {{j, -0.008983550852535105`}, {h,
0.06931364191023386`}}, Method -> "Newton"}
Mathematically, I’m not sure exactly why Netwon’s method fails, but the examples in the documentation for
FindMaximumpoint out this specific problem and error message under Possible Issues: “With machine-precision arithmetic, even functions with smooth maxima may seem bumpy“.Thus, if you increase the working precision with e.g. the
WorkingPrecision -> 20option toFindMaximumthe warnings go away:Given that the text of the error is fairly descriptive:
… I suspect Newton’s method is failing to reached a fixed point with sufficiently small error using machine-precision arithmetic.
As the error message hints, you can instead use the
AccuracyGoaloption to specify the number of significant digits you want in the solution if you don’t want to switch to slower high-precision arithmetic:Hope that helps!