- Notifications
You must be signed in to change notification settings - Fork74
Transforming PyMC models toModelGraph and back#112
-
This started out as an internal discussion some months ago. Since@ricardoV94 has opened#111, I thought that it would be best to condense all of the discussion here and open it up to everyone that is interested. Goal
PyTensor (and What do |
BetaWas this translation helpful?Give feedback.
All reactions
👍 3
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
@lucianopaz thanks for the write-up. My original approach did not introduce the new dummy Value variablesFor others reading the discussion: The value variables define the conditioning points of the logp graph and, possibly, the input variables of a random graph (do-operator, posterior predictive based on traced values). The goal obviously matters, but in general, I think we want to reason explicitly about the "placement" of value variables in our rewrites. To give a concrete example, note that a graph like: withpm.Model()asm:x=pm.Normal.dist()y=pm.Normal.dist()+xm.register_rv(x,"x")m.register_rv(y,"y") Is very different from the following, for the purposes of logp evaluation / MCMC sampling: withpm.Model()asm:x=pm.Normal.dist()y=pm.Normal.dist()z=x+ym.register_rv(x,"x")m.register_rv(y,"y")m.add_named_variable(z,"z")# Deterministic Which is also different than the following (whose logp/ MCMC sampling is currently unsupported by PyMC): withpm.Model()asm:x=pm.Normal.dist()y=pm.Normal.dist()z=x+ym.register_rv(z,"z") The new Other times, our rewrites may be just about changing the conditioning points, without altering anything from the random graph: Again it helps that they are an explicit part of the graph. We can use the same "language" to do these rewrites. It may be worthwhile to note that this type of marker Op's were introduced in the IR reperesentation of Aeppl recently, because we always needed to check that the "source of measurability" was not being conditioned on already. This is a more specific reason related to the logp rewrites, but I think it shows how these markers may be generally useful:aesara-devs/aeppl#78 Some rewrites require manipulating the value variables themselves. Examples: splitting observed/missing components; splitting the initial and innovation steps of a time-series so that they can be sampled separately; removing a value variable during marginalization. Having the variables directly as inputs to these dummy Ops gives us a very natural hook to manipulate them. Old Aeppl and current PyMC had to add a PotentialsI also think it makes a lot of sense to label Potentials, because those correspond to expressions that exist on the logp space, and have nothing to do with the random space. We usually don't want to mess with them when we manipulate "random" graphs. DeterministicsThe exception here is Deterministics! Initially I didn't add a dummy Op for them, and they were just an "un-wrapped" output. I ended up adding them just because it looked cleaner, but I think my initial hunch was correct! Deterministics shouldn't constrain our rewrites at all. I think we should add them as new "copy" outputs, and leave them out of the main random graph. So the following user-defined graph: withpm.Model()asm:x=pm.Normal("x")exp_x=pm.Determinsitic("exp_x",pm.math.exp(x))y=pm.Normal("y",exp_x) Should be represented internally as the following: withpm.Model()asm:x=pm.Normal("x")exp_x=pm.math.exp("x")y=pm.Normal("y",exp_x)pm.Determinsitic("exp_x",exp_x.copy()) We can still add the dummy Deterministic when we put |
BetaWas this translation helpful?Give feedback.