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

Automatically convert PyMC3 Distributions to RandomVariables #110

Open
brandonwillard opened this issue Jun 6, 2020 · 2 comments
Open
Labels
enhancement New feature or request pymc3 This issue relates to PyMC3

Comments

@brandonwillard
Copy link
Contributor

brandonwillard commented Jun 6, 2020

We can create a function that constructs a RandomVariable class for a given PyMC3 Distribution class. The basic requirements are

  1. that Add log-likelihoods to RandomVariables #109 be in place and log_lik = Distribution.logp(out_var),
  2. Distribution.__init__ is utilized in RandomVariable.make_node and its signature is used to determine the signature of RandomVariable.make_node, as well (see the examples here),
  3. and Distribution.random is the backing implementation within RandomVariable.perform.

One complication that comes to mind involves requirement 3.; most implementations of Distribution.random use draw_values, which would be redundant within RandomVariable.perform, since pre-computed samples of all dependent terms already appear as arguments
to RandomVariable.perform. We would have to override draw_values in that context so that it simply returns RandomVariable.perform arguments. It seems like we could use something like mock to accomplish that easily.

@brandonwillard brandonwillard added enhancement New feature or request pymc3 This issue relates to PyMC3 labels Jun 6, 2020
@brandonwillard brandonwillard changed the title Convert PyMC3 Distributions to RandomVariables Automatically convert PyMC3 Distributions to RandomVariables Jun 7, 2020
@brandonwillard
Copy link
Contributor Author

Here's a prototype conversion function that does almost everything mentioned above.

There is a lot of room for error, especially when a Distribution demands test values or uses instance fields in Distribution.random that can't be converted to Theano objects. Both of these are poor practice in general, but the former is effectively required in some situations—I imagine.

@lucianopaz, this is a good starting point for considering class-level Distribution field additions—beyond support and parameter dimension sizes. For instance, while setting up that prototype, I realized that one of the biggest issues is the lack of information about distribution parameters in general. The connections between Distribution.__init__ signatures and the assignments to Distribution.__dict__ aren't strong enough to work with, so perhaps we could add more class-level information like that (e.g. names of essential parameters, or keep a list of said parameters within a class instance, etc.)

@twiecki
Copy link
Member

twiecki commented Jun 9, 2020

This looks really promising!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pymc3 This issue relates to PyMC3
Projects
None yet
Development

No branches or pull requests

2 participants