You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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),
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.
The text was updated successfully, but these errors were encountered:
brandonwillard
changed the title
Convert PyMC3 Distributions to RandomVariables
Automatically convert PyMC3 Distributions to RandomVariables
Jun 7, 2020
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.)
We can create a function that constructs a
RandomVariable
class for a given PyMC3Distribution
class. The basic requirements areRandomVariable
s #109 be in place andlog_lik = Distribution.logp(out_var)
,Distribution.__init__
is utilized inRandomVariable.make_node
and its signature is used to determine the signature ofRandomVariable.make_node
, as well (see the examples here),Distribution.random
is the backing implementation withinRandomVariable.perform
.One complication that comes to mind involves requirement 3.; most implementations of
Distribution.random
usedraw_values
, which would be redundant withinRandomVariable.perform
, since pre-computed samples of all dependent terms already appear as argumentsto
RandomVariable.perform
. We would have to overridedraw_values
in that context so that it simply returnsRandomVariable.perform
arguments. It seems like we could use something likemock
to accomplish that easily.The text was updated successfully, but these errors were encountered: