问题陈述
我有一个工程计算机模型,我手动将长度参数输入其中,并得到应力结果。我希望优化参数,以便:
我设想的工作流程是:
示例数据集
我收集的数据中,我将每个输入参数“Param”更改了两次,得到的结果是“Res”:
尝试使用Scipy optmize.minimize
从我在pyfmi包如何使用它(Section 4.4)中所读到的内容来看,我需要一个无导数的方法,因此默认的Nelder-Mead方法应该可以工作。然而,由于我有不等式,我从SLSQP方法开始This question很有见地,但没有提供充分的信息。下面是我对如何实现这一点的最佳解释。我仍然需要解决如何:
import pandas as pd
from scipy import optimize
# Import values
stress_df = pd.read_excel('test_data.xls') # same as data above
# Objective to minimise
def function (Param_Tft, Param_Tw, Param_Tfb):
""" This is manually entered each time by the user after inputting to the computer model """
print(f'Run computer simulation with Param_Tft={Param_Tft}, Param_Tw={Param_Tw}, Param_Tfb={Param_Tfb}:\n')
Res_TopStress = input('Res_TopStress:')
Res_SideStres = input('Res_SideStress:')
Res_BotStress = input('Res_BotStress:')
# Goal is to aim for zero in the below equation
return Res_TopStress-208 + Res_SideStres-208 + Res_BotStress-208
# Constraints (i.e. stress must equal 208, Param-Tw > 45)
cons = ({'type': 'ineq', 'fun': stress_df['Res_TopStress'] - 208}, # This is probaby a double up of the above function
{'type': 'ineq', 'fun': stress_df['Res_SideStress'] - 208},
{'type': 'ineq', 'fun': stress_df['Res_BotStress'] - 208},
{'type': 'ineq', 'fun': stress_df['Param_Tw'] > 45})
# Non negativity contraints (i.e. for each of three Params)
bnds = ((0, None), (0, None), (0, None))
# Best initial guesses (i.e. for Param-Tft, Param-Tw, Param-Tfb)
Param_0 = [90, 45, 23]
# The optimisation function
res = optimize.minimize(function, Param_0, method='SLSQP', bounds=bnds, constraints=cons)
# Print result
print(res)
我应该如何修改我的代码示例以正确地将问题陈述放入代码中
目前没有回答
相关问题 更多 >
编程相关推荐