第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 lmfit 評(píng)估模型

使用 lmfit 評(píng)估模型

慕容3067478 2022-10-05 18:20:33
我想在輸入變量的定義范圍內(nèi)繪制計(jì)算并繪制模型的預(yù)測(cè),我正在嘗試使用lmfit. 這是我正在處理的代碼。該模型被定義為只有一個(gè)自變量t的函數(shù),但函數(shù)本身也使用另一組獨(dú)立的觀察值。我可以計(jì)算評(píng)估模型的 new_times,但不能對(duì)另一組觀察值做同樣的事情。除了糟糕的配合(這里本身不是問(wèn)題)之外,我還強(qiáng)調(diào)了我在使用時(shí)遇到的錯(cuò)誤,lmfit因?yàn)槲艺J(rèn)為它有效:import numpy as npimport matplotlib.pyplot as pltfrom lmfit import Modelimport scipy.integrate as itimport scipy.constants as sccdef new_f_function(t, sum, f0, a, b, c, T0):  obs_f = f0 + it.cumtrapz(-a * p**c + b, t-T0, initial=0)  new_f = obs_f*(1+sum/scc.c)  return new_f# Create Modelmodel = Model(new_f_function, independent_vars=['t'])# Initialize Parameterparams = model.make_params()params['sum'].value = 1.483 params['sum'].min = 1.47params['sum'].max = 1.50params['f0'].value = 1.483 params['f0'].min = 1.47params['f0'].max = 1.50params['a'].value = 1.483 params['a'].min = 1.47params['a'].max = 1.50params['b'].value = 1.483 params['c'].value = 1.483 params['T0'].value = 1.483 result = model.fit(y_obs, params, weights=(1./y_obs_err), t=times, scale_covar=False)print result.fit_report()# New x-values to evaluate the model x_fit = np.linspace(min(times)-10., max(times)+10, 1e4)  fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1, figsize=(3, 6), sharex='all')ax1.scatter(x=times, y=p, marker='+', c='k')ax2.errorbar(x=times, y=y_obs, yerr=y_obs_err, marker='.', ls='', label='DATA')ax2.plot(times, result.best_fit, label='best fit')new_predictions = result.eval(**result.best_values)#ax2.plot(x_fit, new_predictions, label='extended fit') # This gives error: `ValueError: x and y must have same first dimension, but have shapes (10000,) and (45,)`predicted = result.eval(t=x_fit) # This gives error: `raise ValueError("If given, length of x along axis must be the "ValueError: If given, length of x along axis must be the same as y.`plt.legend()plt.show()我在這里想念什么?
查看完整描述

1 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊

您的錯(cuò)誤消息來(lái)自scipy.integrate.cumtrapz(). 閱讀完整的回溯會(huì)告訴你這一點(diǎn)。該消息是說(shuō) 的兩個(gè)參數(shù)的scipy.integrate.cumtrapz()大小必須相同。

實(shí)際上,it.cumtrapz(-a * p**c + b, t-T0, initial=0)第一個(gè)參數(shù)的大小將由您的變量設(shè)置p,這是一個(gè)固定長(zhǎng)度的數(shù)組,第二個(gè)參數(shù)將由t您的模型函數(shù)的自變量設(shè)置。

因此,當(dāng)您這樣做時(shí)result.eval(t=NEW_ARRAY),如果您的新數(shù)組與您的數(shù)組長(zhǎng)度不同,您肯定會(huì)收到該錯(cuò)誤消息p。那是實(shí)際的錯(cuò)誤。你會(huì)怎么解決?好吧,你必須以某種方式傳入一個(gè)數(shù)組,p因?yàn)樗c新數(shù)組的長(zhǎng)度相同t。

混合全局?jǐn)?shù)組和局部數(shù)組通常是個(gè)壞主意。這說(shuō)明了這樣做的問(wèn)題之一。還有其他一些奇怪的事情會(huì)導(dǎo)致擬合效果不佳。比如a)為什么所有初始值都相同,b)為什么你對(duì)幾個(gè)參數(shù)設(shè)置非常嚴(yán)格(和相同)的界限?我想這些并不是這里真正的問(wèn)題,但它們可能會(huì)使合身效果不太好。


查看完整回答
反對(duì) 回復(fù) 2022-10-05
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)