I have tried that now, and simplified the priors and I get the same problem;
>>> with pm.Model() as model:
... mu = pm.Normal('mu', mu=0, sigma=1)
... obs = pm.Normal('obs', mu=mu, sigma=1, observed=np.random.randn(100))
... trace = pm.sample(1000, tune=500, init="adapt_diag")
...
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [mu]
Sampling 2 chains, 0 divergences: 7%|████▎ | 206/3000 [00:10<02:20, 19.90draws/s]
pymc3.parallel_sampling.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 110, in run
self._start_loop()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 160, in _start_loop
point, stats = self._compute_point()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 191, in _compute_point
point, stats = self._step_method.step(self._point)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/base_hmc.py", line 130, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/quadpotential.py", line 231, in raise_ok
raise ValueError('\n'.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `mu`.ravel()[0] is zero.
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 110, in run
self._start_loop()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 160, in _start_loop
point, stats = self._compute_point()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 191, in _compute_point
point, stats = self._step_method.step(self._point)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/base_hmc.py", line 130, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/quadpotential.py", line 231, in raise_ok
raise ValueError('\n'.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `mu`.ravel()[0] is zero.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/local/lib/python3.7/dist-packages/pymc3/sampling.py", line 469, in sample
trace = _mp_sample(**sample_args)
File "/usr/local/lib/python3.7/dist-packages/pymc3/sampling.py", line 1059, in _mp_sample
for draw in sampler:
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 394, in __iter__
draw = ProcessAdapter.recv_draw(self._active)
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 297, in recv_draw
raise error from old_error
RuntimeError: Chain 1 failed.
I thought this was an interesting insight to what is going wrong, not sure if this is obvious or not, but it seemed informative to me…
>>> from theano.printing import Print as tt_print
>>> with pm.Model() as model:
... mu = pm.Normal('mu', mu=0, sigma=1)
... mu_p = tt_print('mu')(mu)
... obs = pm.Normal('obs', mu=mu_p, sigma=1, observed=np.random.randn(100))
... trace = pm.sample(1000,tune=500, init="adapt_diag")
...
mu __str__ = 0.0
Auto-assigning NUTS sampler...
Initializing NUTS using adapt_diag...
mu __str__ = 0.0
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [mu]
Sampling 2 chains, 0 divergences: 0%| | 0/3000 [00:00<?, ?draws/s]mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
mu __str__ = 0.0
etc., etc., etc.