运行八所示例时失败

时间:2018-03-27 20:39:28

标签: python python-3.x pymc pymc3

我尝试将Eight Schools Model作为一个简单示例运行。具体来说,我试图运行的代码是:

%matplotlib inline
import pymc3 as pm
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sb
import pandas as pd
from collections import defaultdict

plt.style.use('seaborn-darkgrid')
print('Runing on PyMC3 v{}'.format(pm.__version__))

SEED = [20100425, 20100234]

%config InlineBackend.figure_format = 'retina'

# Data of the Eight Schools Model
J = 8
y = np.asarray([28,  8, -3,  7, -1,  1, 18, 12], dtype=float)
sigma = np.asarray([15, 10, 16, 11,  9, 11, 10, 18], dtype=float)
# tau = 25.

with pm.Model() as Centered_eight:
    mu = pm.Normal('mu', mu=0, sd=5)
    tau = pm.HalfCauchy('tau', beta=5)
    theta = pm.Normal('theta', mu=mu, sd=tau, shape=J)
    obs = pm.Normal('obs', mu=theta, sd=sigma, observed=y)

with Centered_eight:
    short_trace = pm.sample(600, chains=2, random_seed=SEED)

但它在最后一行失败了,jupyter笔记本在CMD中给我这个错误):

[I 12:25:24.013 NotebookApp] Kernel started: 137bcad0-e823-487d-a9cb-fc48731f5785
[I 12:25:25.136 NotebookApp] Adapting to protocol v5.1 for kernel 137bcad0-e823-487d-a9cb-fc48731f5785
C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
 55%|███████████████████████████████████████████▏                                  | 609/1100 [00:01<00:01, 336.28it/s]C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
100%|█████████████████████████████████████████████████████████████████████████████| 1100/1100 [00:02<00:00, 407.71it/s]
Process SpawnPoolWorker-3:
Process SpawnPoolWorker-4:
Traceback (most recent call last):
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\process.py", line 258, in _bootstrap
    self.run()
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
Traceback (most recent call last):
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\pool.py", line 108, in worker
    task = get()
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\process.py", line 258, in _bootstrap
    self.run()
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\pool.py", line 360, in get
    racquire()
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
KeyboardInterrupt
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\multiprocessing\pool.py", line 108, in worker
    task = get()
  File "C:\Users\(name)\AppData\Local\Continuum\anaconda3\lib\site-packages\joblib\pool.py", line 360, in get
    racquire()
KeyboardInterrupt
[I 12:26:49.406 NotebookApp] Interrupted...
[I 12:26:49.406 NotebookApp] Shutting down 1 kernel
forrtl: error (200): program aborting due to control-C event
Image              PC                Routine            Line        Source
libifcoremd.dll    00007FFD6DEB94C4  Unknown               Unknown  Unknown
KERNELBASE.dll     00007FFDC0B6717D  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFDC0DC2774  Unknown               Unknown  Unknown
ntdll.dll          00007FFDC38C0D51  Unknown               Unknown  Unknown
forrtl: error (200): program aborting due to control-C event
Image              PC                Routine            Line        Source
libifcoremd.dll    00007FFD6DEB94C4  Unknown               Unknown  Unknown
KERNELBASE.dll     00007FFDC0B6717D  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFDC0DC2774  Unknown               Unknown  Unknown
ntdll.dll          00007FFDC38C0D51  Unknown               Unknown  Unknown
forrtl: error (200): program aborting due to control-C event
Image              PC                Routine            Line        Source
libifcoremd.dll    00007FFD6DEB94C4  Unknown               Unknown  Unknown
KERNELBASE.dll     00007FFDC0B6717D  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFDC0DC2774  Unknown               Unknown  Unknown
ntdll.dll          00007FFDC38C0D51  Unknown               Unknown  Unknown
[I 12:26:49.809 NotebookApp] Kernel shutdown: 137bcad0-e823-487d-a9cb-fc48731f5785

我能够成功运行另外两个示例(linear regressionthe coal mining example),所以我想也许chains中的pm.sample()参数可能会造成麻烦。如果我重新启动内核并运行代码而未指定chains,那么它可以工作。事实上,如果我把链放回来,那么它仍然可以正常工作。但是,如果我启动内核并使用chains运行它,那么我会收到该错误。

所以,我可以使用链运行代码,但除非我先运行它,否则运行代码。看起来幕后的一些缓存可以让我这样做。发生了什么,有没有办法只运行代码而不必像这样做两次?

0 个答案:

没有答案
相关问题