这里的主要思想是了解如何在目标函数定义中使用黑盒函数,以及优化算法如何调用这些函数。在
假设函数定义如下:
f是一个在给定条件下最小化的目标函数问题。让我们说:
f(十一,易)=(艾茜)+(毕喜义)对于n=1,2
式中Yi=N(X1,X2,…Xn)是一个黑盒函数(模拟),其分析形式未知,将所有Xi作为输入
N表示正在模拟的网络。在
Ai和Bi是常数
该问题有以下限制:
X1+X2+…+Xn=C
下面的函数定义只是为了说明我如何调用模拟结果并将其用于优化目标。如果能做得更好,我也愿意接受建议。(但我的主要问题是遵循我的函数定义)
def fun(X):
sim_inpfile(X) # function that has been already defined which is called now by taking x as arguments to write the input file to a simulation
Popen('python Test02.py') # running a python code to execute the simulation
jn.output.Results # Extracting results of simulation by importing a custom made python module called jn
Y=[] # Simulation Result
for i in range(len(jn.output.Results.res)):
if jn.output.Results.res[i].name in nodes:
y += [(jn.output.Results.res[i].pr)] # extracting y as a list from the simulation results
sum = 0 # optimization objective
for i in range(len(a)): # len[a]=len[b]=len[X]=len[Y]
sum += a[i]*X[i]+ b[i]*X[i]*Y[i] #a and b are constants which are lists with the same size as x and y
return sum #the ultimate objective function that takes y(simulation results) as arguments to return the optimization objective value
我现在调用python优化求解器。在
^{pr2}$问题:
对于算法的每次迭代,目标函数是 要求评估?
如果是,我的编码方式是否是返回目标的适当方式
每次迭代时使用黑盒函数求值的函数
解决者?
另外,如果任何python优化包中存在或类似的问题或类似的问题和示例,请共享它们的链接或线程。
感谢您抽出时间,您的经验可能会帮助我解决这个问题。在
这是一个非常广泛的问题,优化是一个非常复杂的主题!所以我只想说几句:
当您调用它时,该函数将在每次迭代中多次调用,因为您没有提供jacobian。SLSQP将使用数值微分来推断它将采取的步进方向(以及它的长度)!在
不,可能没有!在
第一件显而易见的事情是模拟的基于进程的调用,这会导致开销。如果你的模拟在时间上占主导地位,这就不那么相关了,但在这种情况下,这通常是错误的方法。在
其他备注
所以尽管你的问题没有太多细节(细节/假设很重要!),scipy不是实现您想要的最有用的库!有一些关于全局/无导数优化的调查论文(example)概述了备选方案。例如CoinOR的RBFOpt就是一个例子(arrirychoosed;开源),它的页面总结了上面提到的问题:
相关问题 更多 >
编程相关推荐