使用PyMC3拟合帕累托分布

时间:2019-06-27 13:59:07

标签: python bayesian pymc3

我使用以下代码生成一些Pareto分布式数据:

a_true, m = 1.9, 3

test = np.round((np.random.pareto(a_true, 1000)+1)*m)

然后,通过使用PyMC3,我尝试找到alpha和比例参数m的分布:

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)

PyMC3但是返回已知错误:

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:

调试

  • 当我手动将m的值设置为等于3(其真实值)时,PyMC3会非常平滑地采样,并且alpha的分布非常准确。

  • 我还尝试将init参数更改为init = 'adapt_diag'。但是出现相同的错误。

关于可能导致此错误的原因的任何想法。 预先感谢。

0 个答案:

没有答案