pymc-examples icon indicating copy to clipboard operation
pymc-examples copied to clipboard

Dependent density notebook update

Open fonnesbeck opened this issue 1 year ago • 14 comments

Updated code to v5, sampling to NUTS

  • [x] Notebook follows style guide https://docs.pymc.io/en/latest/contributing/jupyter_style.html
  • [ ] PR description contains a link to the relevant issue:
    • a tracker one for existing notebooks (tracker issues have the "tracker id" label)
    • or a proposal one for new notebooks
  • [x] Check the notebook is not excluded from any pre-commit check: https://github.com/pymc-devs/pymc-examples/blob/main/.pre-commit-config.yaml

📚 Documentation preview 📚: https://pymc-examples--706.org.readthedocs.build/en/706/

fonnesbeck avatar Sep 21 '24 01:09 fonnesbeck

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:17Z ----------------------------------------------------------------

Line #9.        beta = pm.Normal("beta", 0.0, 5.0, dims=("one", "K"))

I quite dislike this one dummy dimension. We could eliminate it and use broadcast multiplication instead of a dot product. The dot seems inappropriate -- the shapes appear to be (n_obs, 1), (1, K),which is just an outer product between two vectors. So make everything 1d and use pt.outer.


View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:18Z ----------------------------------------------------------------

Line #10.        x = pm.Data("x", std_range)

Add dims?


View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:19Z ----------------------------------------------------------------

Remove references to PyMC3 here


View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:19Z ----------------------------------------------------------------

Line #4.        mu = pm.Deterministic("mu", gamma + x @ delta)

Same comment as above, delta should have dims=("K",),and write gamma + pt.outer(x, delta)

Also mu is missing dims


View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:20Z ----------------------------------------------------------------

Line #4.        obs = pm.NormalMixture("obs", w, mu, tau=tau, observed=y)

dims on obs (and y)


View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-28T05:36:21Z ----------------------------------------------------------------

Looks like every draw diverged. Going to need to tune this to make it work with NUTS.


Made some comments -- there are a few references to PyMC3 that need to be removed, plus a lot of nitpicks. The biggest problem is in the sampling. Every draw is divergent :( Maybe try nutpie?

jessegrabowski avatar Sep 28 '24 05:09 jessegrabowski

Oof, totally missed the divergences. Odd that the resulting fit was so good.

I tried nutpie and numpyro, but it does not seem to like the stick-breaking piece (even after fixing the outer products). Works okay with Metropolis, so for expediency I'm sticking with this.

fonnesbeck avatar Sep 30 '24 14:09 fonnesbeck

View / edit / reply to this conversation on ReviewNB

jessegrabowski commented on 2024-09-30T14:47:46Z ----------------------------------------------------------------

typo: September 2024


Random question: we have pm.StickBreakingWeights, is that something that could be used for this model instead of the hand-rolled function?

jessegrabowski avatar Sep 30 '24 15:09 jessegrabowski

We would have to reframe the problem somewhat, as StickBreakingWeights models them as a function of a concentration parameter, rather than the linear model used here.

fonnesbeck avatar Sep 30 '24 18:09 fonnesbeck

Ok. That doesn't sound worth it? I was just curious.

jessegrabowski avatar Sep 30 '24 18:09 jessegrabowski

@zaxtax Thanks! Looks like it needs to be re-approved after the fix.

fonnesbeck avatar Jan 19 '25 19:01 fonnesbeck