Pymc3: Feature Request for more informative "Bad Initial Energy"

Created on 18 Oct 2018  路  6Comments  路  Source: pymc-devs/pymc3

Feature Request:
I (and I imagine other users) get a lot of "Bad Initial Energy" errors when first implementing models.
I propose catching this error and adding the equivalent of this code:

for RV in model.basic_RVs:
    print(RV.name, RV.logp(model.test_point))

Maybe something like "Bad Initial Energy, RV [RV_NAME]'s logp is -inf, and appears to be sampling out of bounds" (or out of support or whatever the correct terminology is 馃槈 )
Essentially something to alert the user to which RV might need fixing.

Most helpful comment

Yes, there is a lot to be done in terms of better alerts when things go wrong. PRs welcome :).

All 6 comments

Yes, there is a lot to be done in terms of better alerts when things go wrong. PRs welcome :).

We already have model.check_test_point()

Ok, thanks, guys. If I get some time this weekend i'll give it a go.

I had a look at this today.
I can see the following

``` def _hamiltonian_step(self, start, p0, step_size):
"""Compute one hamiltonian trajectory and return the next state.

    Subclasses must overwrite this method and return a `HMCStepData`.
    """
    raise NotImplementedError("Abstract method")

def astep(self, q0):
    """Perform a single HMC iteration."""
    p0 = self.potential.random()
    start = self.integrator.compute_state(q0, p0)

    if not np.isfinite(start.energy):
        self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
        raise ValueError('Bad initial energy: %s. The model '
                         'might be misspecified.' % start.energy)

```
However I wasn't able in the 30 minutes I looked at it to easily figure out how to replicate the code you were suggesting @bdyetton

Close by #3234

Thanks, guys!!

Was this page helpful?
0 / 5 - 0 ratings