如何获取 scipy.special 函数以将 pymc3 RV 作为输入

我正在尝试使用 pymc3 来拟合涉及 voigt 函数的模型(来自 scipy.special)。voigt 函数的输入应该是数组,而 a,b 是 pymc3 类。如何获得 scipy.special 函数以将 pymc3 RV 作为输入?运行下面附加的代码会产生错误:


import pymc3 as pm

from scipy.special import voigt_profile

import numpy as np


with 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''


慕哥9229398
浏览 200回答 1
1回答

哔哔one

无论好坏,您都需要(重新)使用 theano 实现该功能。这是一个可行的简单版本:注意你不能使用erfc,因为 theano 出错了。import theano.tensor as ttdef 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))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python