我正在尝试使用 1 个共享参数和 6 个其他参数进行全局拟合。dataComplete 是我从文本文件和剂量 = x 值解析的数据。在这里,bValue 随浓度变化而其他保持不变。在进行全局拟合之前,会使用参数进行一些计算。我收到两个错误
1:nan 值和 2:TypeError:输入不当:N=35 不得超过 M=22
我检查了各个元素,它们似乎有效,但不是全局适合。任何帮助都感激不尽。我尝试使用此处先前解决的示例中的代码,但显然有问题。
##file parser
## coded elsewhere
dataComplete = [[90.47, 91.6, 89.83, 68.58, 56.68, 41.93, 1.09, 17.0, 9.19, 1.84, 0.1, 0.38, -0.37, 0.47, 0.65, -0.01, 0.36, 0.18, 0.29, 0.12, 0.87, -1.26], [108.07, 115.49, 102.48, 104.09, 110.15, 72.64, 49.11, 37.35, 24.94, 14.33, 6.31, 3.07, 9.81, 0.2, 0.74, 0.59, 1.11, 0.44, 0.34, 1.03, 0.06, 1.08], [100.93, 118.82, 89.76, 116.32, 127.06, 97.5, 69.71, 47.17, 44.16, 22.15, 18.6, 9.64, 2.56, 2.02, 0.93, 0.29, 1.11, -0.04, 0.27, -0.23, 1.0, 0.18], [99.87, 110.15, 92.21, 92.59, 96.8, 92.69, 81.39, 70.09, 44.08, 39.48, 7.66, 21.49, 2.96, 5.04, 1.87, 2.49, 1.26, 0.53, 0.65, 0.97, 1.15, 0.52], [102.14, 97.94, 94.85, 94.48, 101.22, 94.81, 111.42, 94.96, 61.2, 33.17, 29.37, 11.33, 23.67, 15.97, 6.52, 2.4, 2.29, 0.27, 0.08, 0.31, 0.09, -0.09]]
dose = [-5.0, -5.30103, -5.60206, -5.90309, -6.20412, -6.50515, -6.80618, -7.10721, -7.40824, -7.70927, -8.0103, -8.31133, -8.61236, -8.91339, -9.21442, -9.51545, -9.81648, -10.11751, -10.41854, -10.71957, -11.0206, -11.32163]
def objective(params,xdata,ydata):
resid = 0.0*ydata[:]
for i in range(5):
logEc50 = 10**(params['logEc50_%i' %(i+1)].value)
bValue = params['bValue_%i' %(i+1)].value
pA2 = params['pA2_%i' %(i+1)].value
schildSlope = params['schildSlope_%i' %(i+1)].value
top = params['top_%i' %(i+1)].value
bottom = params['bottom_%i' %(i+1)].value
hillSlope = params['hillSlope_%i' %(i+1)].value
ec50 = 10**(logEc50)
Antag = 1+(bValue/(10**(-1*pA2)))**schildSlope
LogEC=np.log((ec50*Antag))
resid[i, :] =bottom + (top-bottom)/(1+10**((LogEC-dose)*hillSlope))
return resid[i, :] - ydata[i, :]
params = Parameters()
molar = [1.25e-7,2.5e-8,1e-8,5e-9,0]
for i in range(5):
params.add('logEc50_%i' % (i+1),value=-6.96)
params.add('bValue_%i' % (i+1),value=molar[i])
params.add('pA2_%i' % (i+1),value=7.48)
params.add('schildSlope_%i' % (i+1),value=1)
params.add('bottom_%i' % (i+1),value=-0.2)
params.add('top_%i' % (i+1),value=109.496)
params.add('hillSlope_%i' % (i+1),value=1)
#data
dataComplete = [[]]*5
dataComplete[0]=conc1
dataComplete[1]=conc2
dataComplete[2]=conc3
dataComplete[3]=conc4
dataComplete[4]=conc5
print dataComplete
dataComplete = np.array(dataComplete)
assert(dataComplete.shape) ==(5,22)
#x data
dose = np.array(dose)
#fitting
result = minimize(objective,params,args=(dose,dataComplete))
lmfit.printfuncs.report_fit(result.params)