使用pymc.Matplot绘制PyMC模型时出错

时间:2016-08-05 22:57:40

标签: pymc matplotlib

在成功佩戴后使用pymc.Matplot绘制PyMC模型时出现错误

#!/usr/bin/env python2
import pylab
import pymc as pm
import numpy as np

import seir as mod
reload(mod) 

mc = pm.MCMC(mod)
mc.use_step_method(pm.AdaptiveMetropolis, [mod.beta, mod.gamma, mod.s0, mod.eF, mod.i0])
mc.sample(iter = 1000000, burn = 200000, thin = 500, verbose = 1)

Plotting eF


Traceback (most recent call last):

  File "<ipython-input-14-31405478c9cb>", line 1, in <module>
    pm.Matplot.plot(mc)

  File "C:\Users\tele\Anaconda\lib\site-packages\pymc\Matplot.py", line 341, in wrapper
    f(data, name, *args, **kwargs)

  File "C:\Users\tele\Anaconda\lib\site-packages\pymc\Matplot.py", line 455, in plot
    fontmap=fontmap)

  File "C:\Users\tele\Anaconda\lib\site-packages\pymc\Matplot.py", line 377, in wrapper
    f(pymc_obj, *args, **kwargs)

  File "C:\Users\tele\Anaconda\lib\site-packages\pymc\Matplot.py", line 578, in histogram
    hist(data.tolist(), bins, histtype='stepfilled')

  File "C:\Users\tele\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 2958, in hist
    stacked=stacked, data=data, **kwargs)

  File "C:\Users\tele\Anaconda\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
    return func(ax, *args, **kwargs)

  File "C:\Users\tele\Anaconda\lib\site-packages\matplotlib\axes\_axes.py", line 5995, in hist
    m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)

  File "C:\Users\tele\Anaconda\lib\site-packages\numpy\lib\function_base.py", line 249, in histogram
    n += np.bincount(indices, weights=tmp_w, minlength=bins).astype(ntype)

ValueError: operands could not be broadcast together with shapes (11,) (12,) (11,) 

在某些情况下会出现错误,但并非总是如此。由于这是pyMC的内部函数,并且拟合起作用(实际上非​​常好),我不知道该怎么做(顺便说一句,我通常在使用相同的方法调用scores = pm.geweke(mc, intervals=20)时发现另一个错误(不确定是否相关)模型)。

1 个答案:

答案 0 :(得分:0)

刚刚发现错误,抽取numpy数组的愚蠢问题:pyMC崩溃,因为表示可能性的随机变量的均值(模拟)和观察值的大小不相同。 pyMC提供的错误不是很有表现力。