gpt4 book ai didi

optimization - 数学 : Evaluation order during numerical optimisation of black box functions

转载 作者:行者123 更新时间:2023-12-03 15:51:35 26 4
gpt4 key购买 nike

我正在尝试对 Mathematica 中的“黑盒”函数进行数值优化。原理图是这样的:

NMinimize[{comb[x,y,z], x > 0}, {x,y,z}]

其中 comb[x,y,z] 的定义与此类似:
comb[x_,y_,z_] := Module[{},
Print[x,y,z];
M = FindMaximum[SkewNormal[a,x,y,z], {a,x}] // First;
val = f[x,y,z,M];
Return[val];
];

然而,我尝试过的所有最小化函数似乎都没有立即为 comb[x,y,z] 提供数值,它最终试图用 x,y,z 的符号值来评估 FindMaximum(这很容易验证因为 Print[x,y,z] 也象征性地计算)。 Findmaximum 因此失败(FindMaximum::nrnum:函数值等等不是实数),因此最小化失败。

如何修复评估顺序,以便用数值评估 comb 的子功能?

最佳答案

FindMinimum 的评估顺序, FindMaximum , FindRootFindFit记录在 tutorial/UnconstrainedOptimizationSymbolicEvaluation 上文档页面。我认为非常相似的东西适用于 NMinimize功能。描述很长,所以我将在此处仅引用该页面中提出的解决方案:

If your function is such that symbolic evaluation will not keep the function as intended or will be prohibitively slow, you should define your function so that it only evaluates for numerical values of the variables. The simplest way to do this is by defining your function using PatternTest (?), as in f[x_?NumberQ]:=definition.

It may seem that symbolic evaluation just creates a bother since you have to define the function specifically to prevent it. However, without symbolic evaluation, it is hard for Mathematica to take advantage of its unique combination of numerical and symbolic power. Symbolic evaluation means that the commands can consistently take advantage of benefits that come from symbolic analysis, such as algorithm determination, automatic computation of derivatives, automatic optimization and compilation, and structural analysis.

关于optimization - 数学 : Evaluation order during numerical optimisation of black box functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6990285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com