Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic marginalization of finite discrete variables in the logp #91

Merged
merged 3 commits into from
Nov 25, 2022

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Nov 14, 2022

Added a Model transformation, to automatically marginalize discrete variables from the logp graph.

I first attempted to modify the original model in-place so that the FiniteDiscreteMarginalRVs are introduced in the model RV graph, but this led to many issues, in the initial_point, step sampler assignment and so on, which don't really need to know about the modified logp graph.

My latest approach is to clone the underlying model, modify that in place and request its logp, everytime the logp of the user model is requested.

TODO

  • Marginalize finite discrete RVs and replace by SymbolicRV subgraph
  • Suppress annoying RVs missing in graph
    • Fixed by making the marginalized RV part of the subgraph
  • Test nested marginalized RVs
  • Test multiple dependent RVs
    • Aeppl is too restrictive in that it expects one logp-term per value variable, can we group them in a tuple?
  • Test transformed dependent RV
    • Currently not supported due to Aeppl limitations
  • Dispatch default_transform and moment
    • No longer needed because we don't modify the original model
  • Add sampling procedure to retrieve marginalized RVs from prior and posterior
  • Allow Deterministics that don't depend on marginalized RVs
  • Allow Potentials that don't depend on marginalized RVs
  • Fix graphviz for marginalized RVs
    • No longer a problem because we don't modify the original model
  • Fix string representation for marginalized RVs
    • No longer a problem because we don't modify the original model
  • Finish tests
  • Finish docstrings
  • Update PyMC dependency

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@ricardoV94 ricardoV94 force-pushed the marginalize_model branch 2 times, most recently from c19a96f to afd4740 Compare November 14, 2022 18:18
@ricardoV94 ricardoV94 force-pushed the marginalize_model branch 3 times, most recently from 1f0c87e to 4f10d49 Compare November 15, 2022 15:07
@ricardoV94 ricardoV94 force-pushed the marginalize_model branch 2 times, most recently from 9827aab to 3f1d0f4 Compare November 16, 2022 12:46
@ricardoV94 ricardoV94 force-pushed the marginalize_model branch 2 times, most recently from d049eb9 to 75cb830 Compare November 22, 2022 11:15
@ricardoV94 ricardoV94 changed the title Automatic marginalization of discrete variables Automatic marginalization of discrete variables in the logp Nov 22, 2022
@ricardoV94
Copy link
Member Author

This is ready for review, I decided to leave the posterior recovery of marginalized RVs for a subsequent PR as this one is already big as is

@ricardoV94
Copy link
Member Author

Need an approving review :)

@ricardoV94 ricardoV94 changed the title Automatic marginalization of discrete variables in the logp Automatic marginalization of finite discrete variables in the logp Nov 25, 2022
Copy link
Contributor

@zaxtax zaxtax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@twiecki twiecki merged commit 5a01d4f into main Nov 25, 2022
@twiecki twiecki deleted the marginalize_model branch November 25, 2022 14:02
@ricardoV94 ricardoV94 added the enhancements New feature or request label Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancements New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants