我尝试使用pymc3来估计广义逆高斯分布(GIG)的参数,其中涉及贝塞尔函数(来自scipy.special)。bessel函数的输入应该是数组,而alpha,beta,gamma是pymc3类。如何获得scipy. special函数以pymc3 RV作为输入?运行下面附加的代码会产生错误
import pymc3 as pm
from scipy.special import hankel
import numpy as np
def gig(x, a, b, p):
# c = p, is the order
kp = special.hankel1e(p, x)
y1 = ((a / b) ** (p / 2)) / (2 * kp * np.sqrt(a * b))
y2 = (x ** (p - 1)) * np.exp(-(a * x + b / x) / 2)
y = y1 * y2
return y
with pm.Model() as gig_model:
alpha = pm.Gamma('alpha', alpha=0.5, beta=2)
beta = pm.Gamma('beta', alpha=0.5, beta=2)
gamma = pm.Gamma('gamma', alpha=0.5, beta=2)
def giglogp(x):
lp = np.log(GIG(x, alpha, beta, gamma))
return lp
# likelihood
Like = pm.DensityDist('likelihood', giglogp, observed=dt)
TypeError: ufunc 'hankel1e' 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条答案
按热度按时间hkmswyz61#
吴树波,你解决了吗?当我试图从pymc输入一个变量到一个使用scikit-learn的高斯预测的函数时,我也遇到了同样的问题。