numpyro
numpyro copied to clipboard
numpyro.render_model render unexpected graph with handler.do
Similar to #1710. The reproduced code is as follows.
import numpyro
import numpyro.distributions as dist
from numpyro.handlers import do
def model(y=None):
alpha = numpyro.sample("alpha", dist.Normal(0., 1.))
beta = numpyro.sample("beta", dist.Normal(alpha, 1.))
gamma = numpyro.sample("gamma", dist.HalfNormal(beta))
return gamma
intervention = {
"beta": 0.,
}
model_intervention = do(model, intervention)
numpyro.render_model(model_intervention)
This code render the graph below.
But expected is the edge between alpha and beta is cut and the edge between beta and gamma exists.
Yeah, this is an issue. Just curious: will there be a link from alpha to beta? The log density of beta depends on alpha, so I guess there will be a link (like the links from latent variables to the observations). But I'm not sure if there is an interpretation of do
that breaks such a link.
I think it does not make sense to consider the log density of beta under do
.
beta behaves like a constant. I do not understand in detail how numpyro handles variables under do
though.
I guess it implies that beta
is no longer a random variable, so using grey circle might not be correct. Do you have a reference for a graphical model with intervention?
@fehiepsi
Absolutely! But I think there seems to be no established way to describe it.
If you look at this journal Pearl represents the nodes as dots, not sure about the coloring.
I found pymc example. They describe intervened variables using grey circle with assigned value.
Sorry for taking too long responding to this thread. The do operator follows Single World Intervention Graphs semantics so the current graph is expected. But it would be nice to make it clear that gamma
depends on do(beta)
. I'll see what I can do here.
Edit it seems to be tricky because we can't process (hence trace) the intervention message.