0
$\begingroup$

Following PyMC3 code fails:

import pymc3 as pm
with pm.Model():
    pm.Poisson("pois", 10)
    trace = pm.sample(1000, step=pm.Metropolis())

Any idea why? (fails also if I switch to NUTS sampler).

Stack trace:


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in ()
      1 with pm.Model():
      2     pm.Poisson("pois", 10)
----> 3     trace = pm.sample(1000, step=pm.Metropolis())

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\sampling.pyc in sample(draws, step, start, trace, chain, njobs, tune, progressbar, model, random_seed)
    155         sample_func = _sample
    156 
--> 157     return sample_func(**sample_args)
    158 
    159 

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\sampling.pyc in _sample(draws, step, start, trace, chain, tune, progressbar, model, random_seed)
    165         sampling = tqdm(sampling, total=draws)
    166     try:
--> 167         for strace in sampling:
    168             pass
    169     except KeyboardInterrupt:

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\tqdm\_tqdm.pyc in __iter__(self)
    814 """, fp_write=getattr(self.fp, 'write', sys.stderr.write))
    815 
--> 816             for obj in iterable:
    817                 yield obj
    818                 # Update and print the progressbar.

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\sampling.pyc in _iter_sample(draws, step, start, trace, chain, tune, model, random_seed)
    247         if i == tune:
    248             step = stop_tuning(step)
--> 249         point = step.step(point)
    250         strace.record(point)
    251         yield strace

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\step_methods\arraystep.pyc in step(self, point)
    140         bij = DictToArrayBijection(self.ordering, point)
    141 
--> 142         apoint = self.astep(bij.map(point))
    143         return bij.rmap(apoint)
    144 

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\step_methods\metropolis.pyc in astep(self, q0)
    122             q = q0 + delta
    123 
--> 124         q_new = metrop_select(self.delta_logp(q, q0), q, q0)
    125 
    126         if q_new is q:

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in __call__(self, *args, **kwargs)
    869                     node=self.fn.nodes[self.fn.position_of_error],
    870                     thunk=thunk,
--> 871                     storage_map=getattr(self.fn, 'storage_map', None))
    872             else:
    873                 # old-style linkers raise their own exceptions

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\theano\gof\link.pyc in raise_with_op(node, thunk, exc_info, storage_map)
    312         # extra long error message in that case.
    313         pass
--> 314     reraise(exc_type, exc_value, exc_trace)
    315 
    316 

C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in __call__(self, *args, **kwargs)
    857         t0_fn = time.time()
    858         try:
--> 859             outputs = self.fn()
    860         except Exception:
    861             if hasattr(self.fn, 'position_of_error'):

TypeError: expected type_num 9 (NPY_INT64) got 7
Apply node that caused the error: Elemwise{ge,no_inplace}(Subtensor{int64}.0, TensorConstant{0})
Toposort index: 3
Inputs types: [TensorType(int64, scalar), TensorType(int8, scalar)]
Inputs shapes: [(), ()]
Inputs strides: [(), ()]
Inputs values: [array(10), array(0, dtype=int8)]
Outputs clients: [[MakeVector{dtype='int8'}(TensorConstant{1}, Elemwise{ge,no_inplace}.0)]]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer):
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2717, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2821, in run_ast_nodes
    if self.run_code(code, result):
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "", line 2, in 
    pm.Poisson("pois", 10)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\distributions\distribution.py", line 27, in __new__
    return model.Var(name, dist, data)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\model.py", line 276, in Var
    var = FreeRV(name=name, distribution=dist, model=self)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\model.py", line 504, in __init__
    self.logp_elemwiset = distribution.logp(self)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda2\lib\site-packages\pymc3\distributions\discrete.py", line 209, in logp
    mu >= 0, value >= 0)

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
$\endgroup$
7
  • $\begingroup$ Try step=pm.Metropolis() or step=pm.NUTS(). Which version of pymc3 are you running? release or bleeding edge from Github? $\endgroup$ Mar 3, 2017 at 1:48
  • $\begingroup$ Can you also show what kind of error message are you getting? Is Theano installed and working? $\endgroup$ Mar 3, 2017 at 1:49
  • $\begingroup$ PyMC3 version: '3.0.rc2' (running over Win10 Anaconda installation). I tried both samplers - both fail. Theano is working fine (I work with PyMC3 extensively). $\endgroup$
    – MDman
    Mar 3, 2017 at 2:54
  • $\begingroup$ @xeon added stack-trace $\endgroup$
    – MDman
    Mar 3, 2017 at 3:11
  • $\begingroup$ Just run exact your code under Ubuntu 16.10, Anaconda, Python 3.6, PyMC3 release -- no problems. $\endgroup$ Mar 3, 2017 at 3:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.