为什么用牛顿方法的FindMaximum抱怨找不到足够的函数减少量? [英] Why does FindMaximum with Newton's method complain it can't find a sufficient decrease in function?

查看:147
本文介绍了为什么用牛顿方法的FindMaximum抱怨找不到足够的函数减少量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这似乎(从ContourPlot中)是一个相当简单的最大化问题,为什么使用牛顿方法的FindMaximum存在问题?

Firstly, this seems like (from ContourPlot) a fairly straightforward maximization problem, why is FindMaximum with Newton's method having problems?

第二,如何摆脱警告?

第三,如果我不能摆脱这些警告,该如何判断警告是否有意义,即最大化失败?

Thirdly, if I can't get rid of these warnings, how can I tell if the warning is meaningful, ie, maximization failed?

例如,在下面的代码中,使用牛顿方法的FindMaximum会给出警告,而PrincipalAxis方法则不会

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"}

请注意,我认为可能是其中一个分量的方向上的梯度为0的问题,但是如果我干扰了初始点,我仍然会收到相同的警告,这是一个示例

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"}

推荐答案

数学上,我不确定Netwon的方法为什么会失败,但是 With机器精度算术,甚至具有平滑最大值的函数也可能看起来很坎".

Mathematically, I'm not sure exactly why Netwon's method fails, but the examples in the documentation for FindMaximum point out this specific problem and error message under Possible Issues: "With machine-precision arithmetic, even functions with smooth maxima may seem bumpy".

因此,如果您通过以下方式提高工作精度: FindMaximumWorkingPrecision -> 20选项消失了:

Thus, if you increase the working precision with e.g. the WorkingPrecision -> 20 option to FindMaximum the warnings go away:

In[25]:= FindMaximum[o, {{j, 0}, {h, 0}}, Method->"Newton", WorkingPrecision->20]

Out[25]= {-2.0694248079871222533, {j -> -0.14189560954670761863, h -> 0}}

鉴于该错误的文字具有相当的描述性:

Given that the text of the error is fairly descriptive:

FindMaximum :: lstol:线搜索将步长减小到公差范围内 由AccuracyGoal和PrecisionGoal指定,但无法找到足够的增加量 在功能上.您可能需要超过MachinePrecision位数的工作精度才能 满足这些公差. >>

FindMaximum::lstol: The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient increase in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. >>

...我怀疑牛顿的方法无法使用机器精度算法以足够小的误差到达固定点.

... I suspect Newton's method is failing to reached a fixed point with sufficiently small error using machine-precision arithmetic.

如错误消息所提示,如果您不希望切换到较慢的高精度算术,则可以使用AccuracyGoal选项指定解决方案中所需的有效数字位数:

As the error message hints, you can instead use the AccuracyGoal option to specify the number of significant digits you want in the solution if you don't want to switch to slower high-precision arithmetic:

In[27]:= FindMaximum[o, {{j, 0}, {h, 0}}, Method -> "Newton", AccuracyGoal -> 5]

Out[27]= {-2.06942, {j -> -0.141896, h -> -2.78113*10^-17}}

希望有帮助!

这篇关于为什么用牛顿方法的FindMaximum抱怨找不到足够的函数减少量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆