Wolfram mathematica 为什么用牛顿法求最大值';s方法抱怨它可以';你没有发现功能有足够的减少吗?

Wolfram mathematica 为什么用牛顿法求最大值';s方法抱怨它可以';你没有发现功能有足够的减少吗?,wolfram-mathematica,mathematical-optimization,Wolfram Mathematica,Mathematical Optimization,首先,从轮廓图上看,这似乎是一个相当简单的最大化问题,为什么用牛顿法求最大值会有问题 第二,我怎样才能摆脱这些警告呢 第三,如果我不能摆脱这些警告,我如何判断警告是否有意义,即最大化失败 例如,在下面的代码中,使用牛顿方法查找最大值会给出警告,而PrincipalAxis方法不会 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

首先,从轮廓图上看,这似乎是一个相当简单的最大化问题,为什么用牛顿法求最大值会有问题

第二,我怎样才能摆脱这些警告呢

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

例如,在下面的代码中,使用牛顿方法查找最大值会给出警告,而PrincipalAxis方法不会

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"} o=1/5对数[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日志[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对数[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日志[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对数[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对数[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使更多轮廓朝向最大值*) 轮廓函数[n,p]:=函数[{min,max}, 范围=最大值-最小值; 表[Exp[p(x-1)]x范围+min,{x,0,1,1/n}] ]; cf=轮廓函数[10,-1]; 轮廓图@@o,{j,-1,1},{h,-1,1},轮廓->cf} FindMaximum@@@o,{j,0},{h,0},方法->牛顿} FindMaximum@@@o,{j,0},{h,0},方法->“PrincipalAxis”} 注意,我认为可能是其中一个组件方向的梯度为0是问题所在,但如果我扰动初始点,我仍然会得到相同的警告,下面是一个例子

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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Sqrt[2]j)+E^(Sqrt[3]h+Sqrt[2]j)); 等高线图@@o,{j,-1,1},{h,-1,1} FindMaximum@@@o,{{j,-0.0089835508525251055`},{h, 0.06931364191023386`},方法->牛顿}
从数学上讲,我不确定Netwon方法失败的确切原因,但本文中的示例指出了这一特定问题以及可能问题下的错误消息:“使用机器精度算法,即使具有平滑最大值的函数也可能看起来不平稳”

因此,如果使用
WorkingPrecision->20
选项将工作精度提高到
FindMaximum
,警告将消失:

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

Out[25]= {-2.0694248079871222533, {j -> -0.14189560954670761863, h -> 0}}
鉴于错误的文本具有相当的描述性:

FindMaximum::lstol:行搜索将步长减小到公差范围内 由AccuracyGoal和PrecisionGoal指定,但无法找到足够的增加 在函数中。您可能需要超过工作精度的机器精度位数才能 满足这些公差要求。>>

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

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

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

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

希望有帮助

从数学上讲,我不确定Netwon方法失败的确切原因,但本文中的例子指出了这一特定问题和可能问题下的错误信息:“使用机器精度算法,即使具有平滑最大值的函数也可能看起来不稳定”

因此,如果使用
WorkingPrecision->20
选项将工作精度提高到
FindMaximum
,警告将消失:

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

Out[25]= {-2.0694248079871222533, {j -> -0.14189560954670761863, h -> 0}}
鉴于错误的文本具有相当的描述性:

FindMaximum::lstol:行搜索将步长减小到公差范围内 由AccuracyGoal和PrecisionGoal指定,但无法找到足够的增加 在函数中。您可能需要超过工作精度的机器精度位数才能 满足这些公差要求。>>

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

如错误消息hin所示