简体   繁体   English

Scipy 最小化和步长约束

[英]Scipy Minimization and stepsize constraints

I use the scipy.optimize.minimize function and I have a 1D array as x0 with different parameters inside it.我使用scipy.optimize.minimize function 并且我有一个作为x0的一维数组,其中包含不同的参数。 Since I work with different physical parameters, I don't want, for example, to make an iteration of 0.1 for temperature of the order of magnitude of 2500K.由于我使用不同的物理参数,例如,我不希望对 2500K 数量级的温度进行 0.1 的迭代。 So I want to put constraints on the function iterations for each inputs.所以我想对每个输入的 function 迭代施加约束。 I've tried this already:我已经尝试过了:

x0 = [0.1, 10.0, 0.90,1200] #tau,star_diam,amC,Td
bounds = [ [0.005,1],[7,13],[0.05,1], [800,1500] ]

cons = []
for factor in range(len(bounds)):
    lower, upper = bounds[factor]
    l = {'type': 'ineq',
         'fun': lambda x, lb=lower, i=factor: x[i] - lb}
    u = {'type': 'ineq',
         'fun': lambda x, ub=upper, i=factor: ub - x[i]}
    cons.append(l)
    cons.append(u)


res = minimize(DUSTY_RUN,x0,args=(data_charac,lambda_max,lambda_min,DATA_DIR,INPUT_DIR), constraints=cons, method='COBYLA', options={'rhobeg': [0.01,0.01,0.01,100], 'maxiter': 5000, 'disp': False, 'catol': 1e-6})

In the options of the function, the rhoberg option is considered as float , I've tried to change it as a list/array but this didn't change anything as we may guess.在 function 的选项中, rhoberg选项被视为float ,我尝试将其更改为列表/数组,但这并没有像我们猜测的那样改变任何东西。

rhoberg is the initial step, so it doesn't directly control following steps. rhoberg是初始步骤,因此它不直接控制后续步骤。 You can add scaling of parameters in your DUSTY_RUN function - since you wrote [0.01,0.01,0.01,100] you could multiply first three by 1e4 .您可以在DUSTY_RUN function 中添加参数缩放 - 因为您编写了[0.01,0.01,0.01,100]您可以将前三个乘以1e4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM