我正在使用pymc3找到最适合3D表面的东西。这是我正在使用的代码。
with Model() as model:
# specify glm and pass in data. The resulting linear model, its likelihood and
# and all its parameters are automatically added to our model.
glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , flatimage)
start = find_MAP()
step = NUTS(scaling=start) # Instantiate MCMC sampling algorithm
trace = sample(2000, step, progressbar=False) # draw 2000 posterior samples using NUTS sampling
我在这行中遇到错误:
glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , flatimage)
错误是:
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
我试图通过将sin(x)和cos(y)改为np.sin(x)和np.cos(y)来解决这个问题,但这并没有奏效,而且我没有做到。我知道还能做什么。
答案 0 :(得分:1)
我认为问题与您对flatimage
的定义有关。您需要为glm模块标记的数据才能生效。像这样:
# synthetic data (just an example)
x = np.random.normal(size=100)
y = np.random.normal(size=100)
z = x**2 + y**2 + x + y + np.sin(x) + np.cos(y)
data = dict(x=x, y=y, z=z) # a pandas dataframe will also work
with pm.Model() as model:
pm.glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , data)
start = pm.find_MAP()
step = pm.NUTS(scaling=start)
trace = pm.sample(2000, step, start)
查看this示例了解其他详细信息。