Muddling my way through my first PyMC3 model and am running into `SamplingError: Bad Initial Energy`

. It’s not the `inf`

or `nan`

variety, and I’m pretty sure my data don’t contain either as I clean it for infs and nans beforehand. What’s going on?

Here’s the model. `Y`

is the observed data in a `pd.Series`

, `t`

is a predictor also in a series, and `dn`

is an array of series.

```
with pm.Model() as mod:
alpha_0 = pm.Uniform("alpha_0", lower=1e-02, upper=1e02)
delta = pm.Uniform("delta", lower=0.2, upper=5) # CHANGE TO RECIPROCAL IF POSSIBLE
theta = pm.Uniform("theta", lower=5, upper=500)
beta = pm.Uniform("beta", lower=1/duration, upper=10)
b = pm.Uniform("b", lower=0, upper=30)
t0 = pm.Uniform("t0", lower=0, upper=1000)
nba = pm.Uniform("nba", lower=1e-06, upper=1e06)
dist = [(b ** k) * (pm.math.exp(-b)) / tt.gamma(k+1) for k in range(0, len(dn))]
e_dn = pm.math.dot(dist, dn)
alpha_f = alpha_0 * delta
timesens = -(t.to_list()-t0/theta)
alpha = pm.Deterministic("alpha", alpha_0 + 1/(1+ pm.math.exp(timesens)) * (alpha_f - alpha_0))
Y_exp = pm.math.log(beta) - alpha * e_dn
Y_obs = pm.NegativeBinomial("Y_obs", mu=Y_exp, alpha=nba, observed=Y)
```

The model initialises okay, but then when I run `trace = pm.sample(10000, cores=1)`

, I get:

```
---------------------------------------------------------------------------
SamplingError Traceback (most recent call last)
<ipython-input-7-b697c6645656> in <module>
1 with mod:
----> 2 trace = pm.sample(10000, cores=1)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, **kwargs)
455 _log.info('Sequential sampling ({} chains in 1 job)'.format(chains))
456 _print_step_hierarchy(step)
--> 457 trace = _sample_many(**sample_args)
458
459 discard = tune if discard_tuned_samples else 0
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\sampling.py in _sample_many(draws, chain, chains, start, random_seed, step, **kwargs)
501 for i in range(chains):
502 trace = _sample(draws=draws, chain=chain + i, start=start[i],
--> 503 step=step, random_seed=random_seed[i], **kwargs)
504 if trace is None:
505 if len(traces) == 0:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\sampling.py in _sample(chain, progressbar, random_seed, start, draws, step, trace, tune, model, **kwargs)
542 try:
543 strace = None
--> 544 for it, strace in enumerate(sampling):
545 if it >= skip_first:
546 trace = MultiTrace([strace])
~\AppData\Local\Continuum\anaconda3\lib\site-packages\tqdm\std.py in __iter__(self)
1127
1128 try:
-> 1129 for obj in iterable:
1130 yield obj
1131 # Update and possibly print the progressbar.
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\sampling.py in _iter_sample(draws, step, start, trace, chain, tune, model, random_seed)
631 step = stop_tuning(step)
632 if step.generates_stats:
--> 633 point, states = step.step(point)
634 if strace.supports_sampler_stats:
635 strace.record(point, states)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\step_methods\arraystep.py in step(self, point)
245
246 if self.generates_stats:
--> 247 apoint, stats = self.astep(array)
248 point = self._logp_dlogp_func.array_to_full_dict(apoint)
249 return point, stats
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\step_methods\hmc\base_hmc.py in astep(self, q0)
142 )
143 self._warnings.append(warning)
--> 144 raise SamplingError("Bad initial energy")
145
146 adapt_step = self.tune and self.adapt_step_size
SamplingError: Bad initial energy
```

Any ideas what’s happening?