I ran into a similar issue with another model. However, in this case there are some additional errors in quadpotential.py. Seems like its missing some checks for cases where variance/std is 0? Maybe the performance can be improved in such cases if such checks are added (in addition to better initialization)?
import numpy as np
import pymc3 as pm
import theano
import arviz as az
import matplotlib.pyplot as plt
import os
import json
import random
import numpy as np
random.seed(1529142490)
np.random.seed(609648513)
data = dict()
data['y'] =theano.shared(np.array([4.9404,45.0399,14.6792,23.7890,71.7504,29.2036,28.7251,93.7642,28.0774,61.6389,98.5535,94.8738,83.8054,18.4976,39.6836,33.0162,82.1149,35.1902,14.2033,98.9948,35.8724,93.4728,41.8081,26.0160,65.8950,70.1028,8.3385,67.9659,53.5864,6.1922,60.9839,53.0324,98.1783,54.2960,42.7421,9.4019,92.7252,14.3490,20.7931,14.3781,14.2424,14.4019,18.9951,9.3322,99.9797,58.6983,56.7166,87.7854,32.8781,37.4594,11.4034,10.1829,54.8241,82.5061,73.8340,9.3964,57.3845,42.7835,42.0501,97.5864,38.4374,78.7779,50.2264,96.9873,43.3109,80.6796,19.5773,45.3275,29.6839,32.6994,14.0248,10.8371,51.0026,66.8986,102.5188,31.3158,15.1756,46.1974,10.2855,16.6008,51.0629,38.4128,78.3385,85.1597,102.4138,41.2770,98.2303,69.1497,76.7434,84.8919,9.8933,57.5845,8.5367,78.2816,70.9734,6.6665,101.7066,42.4600,47.0682,60.1959]).astype("float64"))
with pm.Model() as model:
x=pm.Lognormal('x',76.4615478515625,93.7094955444336, shape=(100,))
w=pm.Normal('w',10,1)
b=pm.Normal('b',1,1)
sigma=pm.Gamma('sigma',1,2)
obs1=pm.Normal('obs1',w*x+b,sigma, observed=data['y'])
with model:
step = pm.step_methods.hmc.nuts.NUTS(max_treedepth=10,target_accept=0.8,step_scale=0.25)
samples = pm.sample(draws=1000, chains=4, tune=1000, step=step, init="auto", jitter_max_retries=10)
Output:
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
pymc3file.py:31: FutureWarning: In v4.0, pm.sample will return an `arviz.InferenceData` object instead of a `MultiTrace` by default. You can pass return_inferencedata=True or return_inferencedata=False to be safe and silence this warning.
samples = pm.sample(draws=1000, chains=4, tune=1000, step=step, init="auto", jitter_max_retries=10)
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [sigma, b, w, x]
█
pymc/pymc3/step_methods/hmc/quadpotential.py:224: RuntimeWarning: divide by zero encountered in true_divide
np.divide(1, self._stds, out=self._inv_stds)
pymc/pymc3/step_methods/hmc/quadpotential.py:203: RuntimeWarning: invalid value encountered in multiply
return np.multiply(self._var, x, out=out)
pymc/pymc3/step_methods/hmc/quadpotential.py:224: RuntimeWarning: divide by zero encountered in true_divide
np.divide(1, self._stds, out=self._inv_stds)
pymc/pymc3/step_methods/hmc/quadpotential.py:203: RuntimeWarning: invalid value encountered in multiply
return np.multiply(self._var, x, out=out)
pymc/pymc3/step_methods/hmc/quadpotential.py:224: RuntimeWarning: divide by zero encountered in true_divide
np.divide(1, self._stds, out=self._inv_stds)
pymc/pymc3/step_methods/hmc/quadpotential.py:203: RuntimeWarning: invalid value encountered in multiply
return np.multiply(self._var, x, out=out)
pymc/pymc3/step_methods/hmc/quadpotential.py:224: RuntimeWarning: divide by zero encountered in true_divide
np.divide(1, self._stds, out=self._inv_stds)
pymc/pymc3/step_methods/hmc/quadpotential.py:203: RuntimeWarning: invalid value encountered in multiply
return np.multiply(self._var, x, out=out)
pymc3.parallel_sampling.RemoteTraceback:
"""
Traceback (most recent call last):
File "pymc/pymc3/parallel_sampling.py", line 137, in run
self._start_loop()
File "pymc/pymc3/parallel_sampling.py", line 191, in _start_loop
point, stats = self._compute_point()
File "pymc/pymc3/parallel_sampling.py", line 216, in _compute_point
point, stats = self._step_method.step(self._point)
File "pymc/pymc3/step_methods/arraystep.py", line 276, in step
apoint, stats = self.astep(array)
File "pymc/pymc3/step_methods/hmc/base_hmc.py", line 147, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "pymc/pymc3/step_methods/hmc/quadpotential.py", line 272, in raise_ok
raise ValueError("\n".join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `sigma_log__`.ravel()[0] is zero.
The derivative of RV `b`.ravel()[0] is zero.
The derivative of RV `w`.ravel()[0] is zero.
The derivative of RV `x_log__`.ravel()[0] is zero.
The derivative of RV `x_log__`.ravel()[1] is zero.
The derivative of RV `x_log__`.ravel()[2] is zero.
The derivative of RV `x_log__`.ravel()[3] is zero.
The derivative of RV `x_log__`.ravel()[4] is zero.
The derivative of RV `x_log__`.ravel()[5] is zero.
The derivative of RV `x_log__`.ravel()[6] is zero.
The derivative of RV `x_log__`.ravel()[7] is zero.
The derivative of RV `x_log__`.ravel()[8] is zero.
The derivative of RV `x_log__`.ravel()[9] is zero.
The derivative of RV `x_log__`.ravel()[10] is zero.
The derivative of RV `x_log__`.ravel()[11] is zero.
The derivative of RV `x_log__`.ravel()[12] is zero.
The derivative of RV `x_log__`.ravel()[13] is zero.
The derivative of RV `x_log__`.ravel()[14] is zero.
The derivative of RV `x_log__`.ravel()[15] is zero.
The derivative of RV `x_log__`.ravel()[16] is zero.
The derivative of RV `x_log__`.ravel()[17] is zero.
The derivative of RV `x_log__`.ravel()[18] is zero.
The derivative of RV `x_log__`.ravel()[19] is zero.
The derivative of RV `x_log__`.ravel()[20] is zero.
The derivative of RV `x_log__`.ravel()[21] is zero.
The derivative of RV `x_log__`.ravel()[22] is zero.
The derivative of RV `x_log__`.ravel()[23] is zero.
The derivative of RV `x_log__`.ravel()[24] is zero.
The derivative of RV `x_log__`.ravel()[25] is zero.
The derivative of RV `x_log__`.ravel()[26] is zero.
The derivative of RV `x_log__`.ravel()[27] is zero.
The derivative of RV `x_log__`.ravel()[28] is zero.
The derivative of RV `x_log__`.ravel()[29] is zero.
The derivative of RV `x_log__`.ravel()[30] is zero.
The derivative of RV `x_log__`.ravel()[31] is zero.
The derivative of RV `x_log__`.ravel()[32] is zero.
The derivative of RV `x_log__`.ravel()[33] is zero.
The derivative of RV `x_log__`.ravel()[34] is zero.
The derivative of RV `x_log__`.ravel()[35] is zero.
The derivative of RV `x_log__`.ravel()[36] is zero.
The derivative of RV `x_log__`.ravel()[37] is zero.
The derivative of RV `x_log__`.ravel()[38] is zero.
The derivative of RV `x_log__`.ravel()[39] is zero.
The derivative of RV `x_log__`.ravel()[40] is zero.
The derivative of RV `x_log__`.ravel()[41] is zero.
The derivative of RV `x_log__`.ravel()[42] is zero.
The derivative of RV `x_log__`.ravel()[43] is zero.
The derivative of RV `x_log__`.ravel()[44] is zero.
The derivative of RV `x_log__`.ravel()[45] is zero.
The derivative of RV `x_log__`.ravel()[46] is zero.
The derivative of RV `x_log__`.ravel()[47] is zero.
The derivative of RV `x_log__`.ravel()[48] is zero.
The derivative of RV `x_log__`.ravel()[49] is zero.
The derivative of RV `x_log__`.ravel()[50] is zero.
The derivative of RV `x_log__`.ravel()[51] is zero.
The derivative of RV `x_log__`.ravel()[52] is zero.
The derivative of RV `x_log__`.ravel()[53] is zero.
The derivative of RV `x_log__`.ravel()[54] is zero.
The derivative of RV `x_log__`.ravel()[55] is zero.
The derivative of RV `x_log__`.ravel()[56] is zero.
The derivative of RV `x_log__`.ravel()[57] is zero.
The derivative of RV `x_log__`.ravel()[58] is zero.
The derivative of RV `x_log__`.ravel()[59] is zero.
The derivative of RV `x_log__`.ravel()[60] is zero.
The derivative of RV `x_log__`.ravel()[61] is zero.
The derivative of RV `x_log__`.ravel()[62] is zero.
The derivative of RV `x_log__`.ravel()[63] is zero.
The derivative of RV `x_log__`.ravel()[64] is zero.
The derivative of RV `x_log__`.ravel()[65] is zero.
The derivative of RV `x_log__`.ravel()[66] is zero.
The derivative of RV `x_log__`.ravel()[67] is zero.
The derivative of RV `x_log__`.ravel()[68] is zero.
The derivative of RV `x_log__`.ravel()[69] is zero.
The derivative of RV `x_log__`.ravel()[70] is zero.
The derivative of RV `x_log__`.ravel()[71] is zero.
The derivative of RV `x_log__`.ravel()[72] is zero.
The derivative of RV `x_log__`.ravel()[73] is zero.
The derivative of RV `x_log__`.ravel()[74] is zero.
The derivative of RV `x_log__`.ravel()[75] is zero.
The derivative of RV `x_log__`.ravel()[76] is zero.
The derivative of RV `x_log__`.ravel()[77] is zero.
The derivative of RV `x_log__`.ravel()[78] is zero.
The derivative of RV `x_log__`.ravel()[79] is zero.
The derivative of RV `x_log__`.ravel()[80] is zero.
The derivative of RV `x_log__`.ravel()[81] is zero.
The derivative of RV `x_log__`.ravel()[82] is zero.
The derivative of RV `x_log__`.ravel()[83] is zero.
The derivative of RV `x_log__`.ravel()[84] is zero.
The derivative of RV `x_log__`.ravel()[85] is zero.
The derivative of RV `x_log__`.ravel()[86] is zero.
The derivative of RV `x_log__`.ravel()[87] is zero.
The derivative of RV `x_log__`.ravel()[88] is zero.
The derivative of RV `x_log__`.ravel()[89] is zero.
The derivative of RV `x_log__`.ravel()[90] is zero.
The derivative of RV `x_log__`.ravel()[91] is zero.
The derivative of RV `x_log__`.ravel()[92] is zero.
The derivative of RV `x_log__`.ravel()[93] is zero.
The derivative of RV `x_log__`.ravel()[94] is zero.
The derivative of RV `x_log__`.ravel()[95] is zero.
The derivative of RV `x_log__`.ravel()[96] is zero.
The derivative of RV `x_log__`.ravel()[97] is zero.
The derivative of RV `x_log__`.ravel()[98] is zero.
The derivative of RV `x_log__`.ravel()[99] is zero.
"""
The above exception was the direct cause of the following exception:
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `sigma_log__`.ravel()[0] is zero.
The derivative of RV `b`.ravel()[0] is zero.
The derivative of RV `w`.ravel()[0] is zero.
The derivative of RV `x_log__`.ravel()[0] is zero.
The derivative of RV `x_log__`.ravel()[1] is zero.
The derivative of RV `x_log__`.ravel()[2] is zero.
The derivative of RV `x_log__`.ravel()[3] is zero.
The derivative of RV `x_log__`.ravel()[4] is zero.
The derivative of RV `x_log__`.ravel()[5] is zero.
The derivative of RV `x_log__`.ravel()[6] is zero.
The derivative of RV `x_log__`.ravel()[7] is zero.
The derivative of RV `x_log__`.ravel()[8] is zero.
The derivative of RV `x_log__`.ravel()[9] is zero.
The derivative of RV `x_log__`.ravel()[10] is zero.
The derivative of RV `x_log__`.ravel()[11] is zero.
The derivative of RV `x_log__`.ravel()[12] is zero.
The derivative of RV `x_log__`.ravel()[13] is zero.
The derivative of RV `x_log__`.ravel()[14] is zero.
The derivative of RV `x_log__`.ravel()[15] is zero.
The derivative of RV `x_log__`.ravel()[16] is zero.
The derivative of RV `x_log__`.ravel()[17] is zero.
The derivative of RV `x_log__`.ravel()[18] is zero.
The derivative of RV `x_log__`.ravel()[19] is zero.
The derivative of RV `x_log__`.ravel()[20] is zero.
The derivative of RV `x_log__`.ravel()[21] is zero.
The derivative of RV `x_log__`.ravel()[22] is zero.
The derivative of RV `x_log__`.ravel()[23] is zero.
The derivative of RV `x_log__`.ravel()[24] is zero.
The derivative of RV `x_log__`.ravel()[25] is zero.
The derivative of RV `x_log__`.ravel()[26] is zero.
The derivative of RV `x_log__`.ravel()[27] is zero.
The derivative of RV `x_log__`.ravel()[28] is zero.
The derivative of RV `x_log__`.ravel()[29] is zero.
The derivative of RV `x_log__`.ravel()[30] is zero.
The derivative of RV `x_log__`.ravel()[31] is zero.
The derivative of RV `x_log__`.ravel()[32] is zero.
The derivative of RV `x_log__`.ravel()[33] is zero.
The derivative of RV `x_log__`.ravel()[34] is zero.
The derivative of RV `x_log__`.ravel()[35] is zero.
The derivative of RV `x_log__`.ravel()[36] is zero.
The derivative of RV `x_log__`.ravel()[37] is zero.
The derivative of RV `x_log__`.ravel()[38] is zero.
The derivative of RV `x_log__`.ravel()[39] is zero.
The derivative of RV `x_log__`.ravel()[40] is zero.
The derivative of RV `x_log__`.ravel()[41] is zero.
The derivative of RV `x_log__`.ravel()[42] is zero.
The derivative of RV `x_log__`.ravel()[43] is zero.
The derivative of RV `x_log__`.ravel()[44] is zero.
The derivative of RV `x_log__`.ravel()[45] is zero.
The derivative of RV `x_log__`.ravel()[46] is zero.
The derivative of RV `x_log__`.ravel()[47] is zero.
The derivative of RV `x_log__`.ravel()[48] is zero.
The derivative of RV `x_log__`.ravel()[49] is zero.
The derivative of RV `x_log__`.ravel()[50] is zero.
The derivative of RV `x_log__`.ravel()[51] is zero.
The derivative of RV `x_log__`.ravel()[52] is zero.
The derivative of RV `x_log__`.ravel()[53] is zero.
The derivative of RV `x_log__`.ravel()[54] is zero.
The derivative of RV `x_log__`.ravel()[55] is zero.
The derivative of RV `x_log__`.ravel()[56] is zero.
The derivative of RV `x_log__`.ravel()[57] is zero.
The derivative of RV `x_log__`.ravel()[58] is zero.
The derivative of RV `x_log__`.ravel()[59] is zero.
The derivative of RV `x_log__`.ravel()[60] is zero.
The derivative of RV `x_log__`.ravel()[61] is zero.
The derivative of RV `x_log__`.ravel()[62] is zero.
The derivative of RV `x_log__`.ravel()[63] is zero.
The derivative of RV `x_log__`.ravel()[64] is zero.
The derivative of RV `x_log__`.ravel()[65] is zero.
The derivative of RV `x_log__`.ravel()[66] is zero.
The derivative of RV `x_log__`.ravel()[67] is zero.
The derivative of RV `x_log__`.ravel()[68] is zero.
The derivative of RV `x_log__`.ravel()[69] is zero.
The derivative of RV `x_log__`.ravel()[70] is zero.
The derivative of RV `x_log__`.ravel()[71] is zero.
The derivative of RV `x_log__`.ravel()[72] is zero.
The derivative of RV `x_log__`.ravel()[73] is zero.
The derivative of RV `x_log__`.ravel()[74] is zero.
The derivative of RV `x_log__`.ravel()[75] is zero.
The derivative of RV `x_log__`.ravel()[76] is zero.
The derivative of RV `x_log__`.ravel()[77] is zero.
The derivative of RV `x_log__`.ravel()[78] is zero.
The derivative of RV `x_log__`.ravel()[79] is zero.
The derivative of RV `x_log__`.ravel()[80] is zero.
The derivative of RV `x_log__`.ravel()[81] is zero.
The derivative of RV `x_log__`.ravel()[82] is zero.
The derivative of RV `x_log__`.ravel()[83] is zero.
The derivative of RV `x_log__`.ravel()[84] is zero.
The derivative of RV `x_log__`.ravel()[85] is zero.
The derivative of RV `x_log__`.ravel()[86] is zero.
The derivative of RV `x_log__`.ravel()[87] is zero.
The derivative of RV `x_log__`.ravel()[88] is zero.
The derivative of RV `x_log__`.ravel()[89] is zero.
The derivative of RV `x_log__`.ravel()[90] is zero.
The derivative of RV `x_log__`.ravel()[91] is zero.
The derivative of RV `x_log__`.ravel()[92] is zero.
The derivative of RV `x_log__`.ravel()[93] is zero.
The derivative of RV `x_log__`.ravel()[94] is zero.
The derivative of RV `x_log__`.ravel()[95] is zero.
The derivative of RV `x_log__`.ravel()[96] is zero.
The derivative of RV `x_log__`.ravel()[97] is zero.
The derivative of RV `x_log__`.ravel()[98] is zero.
The derivative of RV `x_log__`.ravel()[99] is zero.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "pymc3file.py", line 31, in <module>
samples = pm.sample(draws=1000, chains=4, tune=1000, step=step, init="auto", jitter_max_retries=10)
File "pymc/pymc3/sampling.py", line 559, in sample
trace = _mp_sample(**sample_args, **parallel_args)
File "pymc/pymc3/sampling.py", line 1477, in _mp_sample
for draw in sampler:
File "pymc/pymc3/parallel_sampling.py", line 479, in __iter__
draw = ProcessAdapter.recv_draw(self._active)
File "pymc/pymc3/parallel_sampling.py", line 359, in recv_draw
raise error from old_error
RuntimeError: Chain 1 failed.