When I sample a Binomial module which is:
n=127
y=14
with pm.Model() as m_valid:
# a priori
theta = pm.Beta('theta', alpha=1, beta=1)
# likelihood
obs = pm.Binomial('observed', n=n, p=theta, observed=y)
#sampling
trace_m_valid = pm.sample(1000)
It will meet ‘Bad initial energy’
The strange thing is, only n=127 the error will occur, other number say n=126, n=129 all OK,
Why n=127 is so strange?
the error detail is:
Auto-assigning NUTS sampler…
Initializing NUTS using jitter+adapt_diag…
Multiprocess sampling (4 chains in 4 jobs)
NUTS: [theta]
Sampling 4 chains: 0%| | 0/6000 [00:00<?, ?draws/s]/home/huwendi/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.
out=out, **kwargs)
/home/huwendi/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.
out=out, **kwargs)
/home/huwendi/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.
out=out, **kwargs)
/home/huwendi/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.
out=out, **kwargs)
Bad initial energy, check any log probabilities that are inf or -inf, nan or very small:
observed inf
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
“”"
Traceback (most recent call last):
File “/home/huwendi/anaconda3/lib/python3.7/site-packages/pymc3/parallel_sampling.py”, line 123, in _start_loop
point, stats = self._compute_point()
File “/home/huwendi/anaconda3/lib/python3.7/site-packages/pymc3/parallel_sampling.py”, line 154, in _compute_point
point, stats = self._step_method.step(self._point)
File “/home/huwendi/anaconda3/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py”, line 247, in step
apoint, stats = self.astep(array)
File “/home/huwendi/anaconda3/lib/python3.7/site-packages/pymc3/step_methods/hmc/base_hmc.py”, line 149, in astep
raise SamplingError(“Bad initial energy”)
pymc3.exceptions.SamplingError: Bad initial energy
“”"
The above exception was the direct cause of the following exception:
SamplingError Traceback (most recent call last)
SamplingError: Bad initial energy
The above exception was the direct cause of the following exception:
ParallelSamplingError Traceback (most recent call last)
in ()
10 obs = pm.Binomial(‘observed’, n=n, p=theta, observed=y)
11 #sampling
—> 12 trace_m_valid = pm.sample(1000)
~/anaconda3/lib/python3.7/site-packages/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, discard_tuned_samples, live_plot_kwargs, compute_convergence_checks, use_mmap, **kwargs)
437 _print_step_hierarchy(step)
438 try:
–> 439 trace = _mp_sample(**sample_args)
440 except pickle.PickleError:
441 _log.warning(“Could not pickle model, sampling singlethreaded.”)
~/anaconda3/lib/python3.7/site-packages/pymc3/sampling.py in _mp_sample(draws, tune, step, chains, cores, chain, random_seed, start, progressbar, trace, model, use_mmap, **kwargs)
988 try:
989 with sampler:
–> 990 for draw in sampler:
991 trace = traces[draw.chain - chain]
992 if (trace.supports_sampler_stats
~/anaconda3/lib/python3.7/site-packages/pymc3/parallel_sampling.py in iter(self)
343
344 while self._active:
–> 345 draw = ProcessAdapter.recv_draw(self._active)
346 proc, is_last, draw, tuning, stats, warns = draw
347 if self._progress is not None:
~/anaconda3/lib/python3.7/site-packages/pymc3/parallel_sampling.py in recv_draw(processes, timeout)
247 else:
248 error = RuntimeError(“Chain %s failed.” % proc.chain)
–> 249 six.raise_from(error, old_error)
250 elif msg[0] == “writing_done”:
251 proc._readable = True
~/anaconda3/lib/python3.7/site-packages/six.py in raise_from(value, from_value)
ParallelSamplingError: Bad initial energy
Thanks!