为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕哥9229398 2022-10-11 21:12:32
我正在尝试使用 pymc3 来拟合涉及 voigt 函数的模型(来自 scipy.special)。voigt 函数的输入应该是数组,而 a,b 是 pymc3 类。如何获得 scipy.special 函数以将 pymc3 RV 作为输入?运行下面附加的代码会产生错误: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贡献1854条经验 获得超8个赞

无论好坏,您都需要(重新)使用 theano 实现该功能。这是一个可行的简单版本:注意你不能使用erfc,因为 theano 出错了。


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))


查看完整回答
反对 回复 2022-10-11
  • 1 回答
  • 0 关注
  • 154 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号