我正在通过回归示例探索 PyMC3。我从一条直线开始,然后转到二次曲线,效果很好。当我尝试移动到其中包含随机变量的正弦函数时,尽管事情变糟了。
这是我的 PyMC3 代码:
import pymc as pm
import numpy as np
trace = None
with pm.Model() as model:
alpha = pm.Normal('alpha', mu=0, sd=20)
beta = pm.Normal('beta', mu=0, sd=20)
mewmew = pm.Normal('mewmew', mu=0, sd=20)
sigma = pm.Uniform('sigma', lower=0, upper=20)
y_est = alpha + beta * numpy.sin(mewmew * x)
likelihood = pm.Normal('y', mu=y_est, sd=sigma, observed=y)
start = pm.find_MAP()
step = pm.NUTS(state=start)
trace = pm.sample(2000, step, start=start, progressbar=False)
pm.traceplot(trace);
我收到此错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-139-60a584151c07> in <module>()
9 sigma = pm.Uniform('sigma', lower=0, upper=20)
10
---> 11 y_est = alpha + beta * numpy.sin(mewmew * x)
12
13 likelihood = pm.Normal('y', mu=y_est, sd=sigma, observed=y)
AttributeError: sin
提前致谢!