# How to debug Bad initial energy: nan?

**URL:** <https://discourse.pymc.io/t/how-to-debug-bad-initial-energy-nan/492>\
**Category:** Questions\
**Created:** [October 25, 2017, 2:52pm UTC](https://discourse.pymc.io/t/how-to-debug-bad-initial-energy-nan/492 "2017-10-25T14:52:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 25, 2017, 3:11pm UTC](https://discourse.pymc.io/t/how-to-debug-bad-initial-energy-nan/492/2 "2017-10-25T15:11:21Z")

</div>

Have you try the solution in FAQ?

> [@Frequently Asked Questions](https://discourse.pymc.io/t/frequently-asked-questions/74/5):
>
> Getting NaN or Inf during NUTS or VI (e.g., 'Bad initial energy: inf. The model might be misspecified., NaN occurred in optimization.)

> [@Getting 'Bad initial energy: inf' when trying to sample simple model](https://discourse.pymc.io/t/getting-bad-initial-energy-inf-when-trying-to-sample-simple-model/364/2):
>
> Hi @Stargrazer82301, this is actually one of our FAQs. You can have a look at the answer here: For example, in your case, running: for RV in model.basic\_RVs: print(RV.name, RV.logp(model.test\_point)) gives: Intercept 1.1370228148748596 Gradient -inf Psi\_log\_\_ -0.7257913526447277 z\_likelihood 73.49976264100106 And looking closer at gradient: gradient = pm.Normal('Gradient', mu=leastsq\_fit[0], sd=leastsq\_fit[0], testval=leastsq\_fit[0]) You can see that sd is defined as leastsq\_fit[0], …

---

_[View the full topic](https://discourse.pymc.io/t/how-to-debug-bad-initial-energy-nan/492)._
