我正在嘗試使用 pymc3 來(lái)擬合涉及 voigt 函數(shù)的模型(來(lái)自 scipy.special)。voigt 函數(shù)的輸入應(yīng)該是數(shù)組,而 a,b 是 pymc3 類。如何獲得 scipy.special 函數(shù)以將 pymc3 RV 作為輸入?運(yùn)行下面附加的代碼會(huì)產(chǎn)生錯(cuò)誤:import pymc3 as pmfrom scipy.special import voigt_profileimport numpy as npwith pm.Model() as linear_model: a = pm.Lognormal('a',mu=0, sigma=2.) b = pm.Lognormal('b',mu=0, sigma=2.) x = np.linspace(-1,1) c = voigt_profile(x,a,b)TypeError: ufunc 'voigt_profile' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
1 回答
嗶嗶one
TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
無(wú)論好壞,您都需要(重新)使用 theano 實(shí)現(xiàn)該功能。這是一個(gè)可行的簡(jiǎn)單版本:注意你不能使用erfc,因?yàn)?theano 出錯(cuò)了。
import theano.tensor as tt
def faddeeva(z):
m = tt.exp(-tt.square(z))
return (m - m * tt.erf(1.j * z))
def voigt_profile(x, sigma, gamma):
z = (x + 1.j * gamma) / (tt.sqrt(2.) * sigma)
return faddeeva(z).real / (sigma * tt.sqrt(2 * np.pi))
添加回答
舉報(bào)
0/150
提交
取消
