Mathematica:黑盒函数数值优化期间的评估顺序 [英] Mathematica: Evaluation order during numerical optimisation of black box functions

查看:122
本文介绍了Mathematica:黑盒函数数值优化期间的评估顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对Mathematica中的黑匣子"函数进行数值优化.原理上是这样的:

I am attempting to perform a numerical optimisation of a "black box" function in Mathematica. Schematically it goes like this:

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

其中comb [x,y,z]的定义与此类似:

where comb[x,y,z] is defined similarly to this:

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:函数值blah blah不是实数),因此最小化失败.

However, all of the minimisation functions I have tried seem to not immediately provide comb[x,y,z] with numerical values, and it ends up trying to evaluate the FindMaximum with symbolic values for x,y,z (which is easily verified because the Print[x,y,z] also evaluates symbolically). The Findmaximum thus fails (FindMaximum::nrnum: The function value blah blah is not a real number) and so the minimisation fails.

如何确定评估顺序,以便用数值评估梳子的子功能?

How do I fix up the evaluation order so that the sub-functions of comb are evaluated with numerical values?

推荐答案

FindMinimumFindMaximumFindRootFindFit的评估顺序记录在

Evaluation order for FindMinimum, FindMaximum, FindRoot and FindFit is documented on the tutorial/UnconstrainedOptimizationSymbolicEvaluation Documentation page. I think that something very similar is applicable to the NMinimize function. The description is quite lengthy so I will cite here only the proposed solution from that page:

如果您的函数使符号求值不能保持 预期的功能或将变得缓慢,您应该定义 您的函数,以便仅计算 变量.最简单的方法是定义函数 使用PatternTest(?),如f [x_?NumberQ]:=定义.

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.

由于您 必须专门定义该功能以防止该功能.然而, 没有符号评估,Mathematica很难接受 其独特的数字和符号能力组合的优势. 符号评估意味着命令可以始终如一地执行 从符号分析中受益的优势,例如 算法确定,导数的自动计算, 自动优化和编译以及结构分析.

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.

这篇关于Mathematica:黑盒函数数值优化期间的评估顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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