Fit Pareto Distribution fails: Bad initial Energy

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 initparamater to init = 'adapt_diag'. I get the same error.
Any idea of what I might be doing wrong.
Thanks in advance.

Looks like it is related to the initial condition of the chain, what is the output if you do:

pareto.check_test_point()

Thanks for your quick answer.
The output is:

m_interval__       -1.390000
alpha_interval__   -1.390000
yhat                    -inf
Name: Log-probability of test_point, dtype: float64

However, I have realised that if I narrow down the upper values for m, it samples correctly. I wanted to use a completely uninformative prior, but probably it was sampling values that were not compatible with the distribution.

You can also try setting the testval of mu - if you are seeing -inf running model.test_point(), it is an indication that some parameter is in a bad state. Of course in general if that happens you should change your prior but setting the testval is a relatively quick fix.

1 Like