【发布时间】:2023-01-19 23:42:26
【问题描述】:
我正在尝试使用 shgo 算法来运行模拟(黑盒问题)并最大化模拟的输出参数。目标函数运行并评估模拟。 我有 5 个变量作为输入。我需要定义边界和约束,这是限制模拟几何形状所必需的。 由于这是一个有很多变量的问题,我需要一个全局优化器,它接受边界和约束。因此 shgo 似乎非常合适。 但是,我正在努力让优化器算法接受我的边界和约束并收敛。
这是我的优化代码:
bnds = [(50*1e-9,500*1e-9), (50*1e-9,500*1e-9), (1,20), (20*1e-9,80*1e-9), (250*1e-9,800*1e-9)]
def constraint1(x):
return x[4]-50*1e-9-2*x[0] # x[4]<=2*x[0]-50nm(threshold)
def constraint2(x):
return x[1]-x[3]-20*1e-9 # x[1]-x[3]>=20nm(threshold)
def constraint3(x):
return x[0]-(x[1]/2)*(2.978/x[2])-20*1e-9
cons = ({'type': 'ineq', 'fun': constraint1},
{'type': 'ineq', 'fun': constraint2},
{'type': 'ineq', 'fun': constraint3})
minimizer_kwargs = {'method':'COBYLA',
'bounds': bnds,
'constraints':cons}
opts = {'disp':True}
res_shgo = shgo(objective,
bounds=bnds,
constraints=cons,
sampling_method='sobol',
minimizer_kwargs=minimizer_kwargs,
options=opts)
全局算法运行 33 轮以完成评估并启动最小化池:
Evaluations completed.
Search for minimiser pool
--- Starting minimization at [3.3828125e-07 4.6484375e-07 1.1984375e+01 6.7812500e-08 7.5703125e-07]...
现在,COBYLA 算法在最小化池中用于最小化。然而,几轮之后它超出了边界,结果是输入参数导致我的模拟崩溃。
我还尝试了最小化池的“L-BFGS-B”算法。
minimizer_kwargs = {'method':'L-BFGS-B'}
算法收敛于以下语句:
lres = fun: -20.247226776119533
hess_inv: <5x5 LbfgsInvHessProduct with dtype=float64>
jac: array([ 1.70730429e+09, 1.22968297e+09, 0.00000000e+00, -1.82566323e+09,
1.83071706e+09])
message: 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
nfev: 6
nit: 0
njev: 1
status: 0
success: True
x: array([2.43359375e-07, 2.99609375e-07, 1.48046875e+01, 7.01562500e-08,
6.23828125e-07])
Minimiser pool = SHGO.X_min = []
Successfully completed construction of complex.
结果不是全局最小值。
我怎样才能使 shgo 最好用 COBYLA 成功终止。
【问题讨论】:
标签: python optimization scipy-optimize shgo