pymc3 unexplainable TypeError when creating pm.Normal variable

时间:2019-01-18 18:11:43

标签: python pymc3

The following code is taken from numerous examples of simple pymc3 usage:

import os
os.environ['MKL_THREADING_LAYER'] = 'GNU'
import pymc3 as pm
with pm.Model() as model:
    alpha = pm.Normal('alpha', mu=0, sigma=1)

For some reason, it throws the following exception:

Traceback (most recent call last):
   File "test2.py", line 5, in <module>
    alpha = pm.Normal('alpha', mu=0, sigma=1)
  File "C:\Users\%USERNAME%\AppData\Local\Continuum\anaconda3\lib\site- 
packages\pymc3\distributions\distribution.py", line 41, in __new__
    dist = cls.dist(*args, **kwargs)
  File "C:\Users\%USERNAME%\AppData\Local\Continuum\anaconda3\lib\site- 
packages\pymc3\distributions\distribution.py", line 52, in dist
    dist.__init__(*args, **kwargs)
  File "C:\Users\%USERNAME%\AppData\Local\Continuum\anaconda3\lib\site- 
packages\pymc3\distributions\continuous.py", line 404, in __init__
    super(Normal, self).__init__(**kwargs)
  File "C:\Users\%USERNAME%\AppData\Local\Continuum\anaconda3\lib\site- 
packages\pymc3\distributions\distribution.py", line 180, in __init__
    shape, dtype, defaults=defaults, *args, **kwargs)
 TypeError: __init__() got an unexpected keyword argument 'sigma'

What is the cause of this error?

I have tried with both version 3.5 and 3.6 and pymc3.

1 个答案:

答案 0 :(得分:1)

您应该使用sd而不是sigma:

import os
os.environ['MKL_THREADING_LAYER'] = 'GNU'
import pymc3 as pm
with pm.Model() as model:
    alpha = pm.Normal('alpha', mu=0, sd=1)

这对我有用:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['MKL_THREADING_LAYER'] = 'GNU'
>>> import pymc3 as pm
>>> with pm.Model() as model:
...     alpha = pm.Normal('alpha', mu=0, sd=1)
... 
>>>