Hi there,
I want to compute the posterior distribution for the scaling exponent of a Pareto Distribution. To test everything works fine, I first generate same sample data:
a_true, m = 1.9, 3
test = np.round((np.random.pareto(a_true, 1000)+1)*m)
Then, I try to find the posterior for alpha
.:
pareto = pm.Model()
with pareto:
m = pm.Uniform('m', lower = 0, upper = 10)
alpha = pm.Uniform('alpha', lower = 1, upper = 5)
yhat = pm.Pareto('yhat', m = m, alpha = alpha, observed = test)
trace_pareto = pm.sample(10000,tune=1000)
However, PyMC returns the Bad Initial Energy
Error:
uto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [alpha, m]
Sampling 4 chains: 0%| | 0/44000 [00:00<?, ?draws/s]
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 73, in run
self._start_loop()
File "/usr/local/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 113, in _start_loop
point, stats = self._compute_point()
File "/usr/local/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 139, in _compute_point
point, stats = self._step_method.step(self._point)
File "/usr/local/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/usr/local/lib/python3.7/site-packages/pymc3/step_methods/hmc/base_hmc.py", line 117, in astep
'might be misspecified.' % start.energy)
ValueError: Bad initial energy: inf. The model might be misspecified.
"""
The above exception was the direct cause of the following exception:
Debugging
However, when I manually set the value of m
equal to 3, PyMC3 samples completely smoothly:
pareto = pm.Model()
with pareto:
alpha = pm.Uniform('alpha', lower = 1, upper = 5)
yhat = pm.Pareto('yhat', m = 3, alpha = alpha, observed = test)
trace_pareto = pm.sample(10000,tune=1000)
I have also tried to change the init
paramater to init = 'adapt_diag'
. I get the same error.
Any idea of what I might be doing wrong.
Thanks in advance.