numpyro icon indicating copy to clipboard operation
numpyro copied to clipboard

numpyro.render_model render unexpected graph with handler.do

Open yayami3 opened this issue 1 year ago • 5 comments

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. model_intervention

But expected is the edge between alpha and beta is cut and the edge between beta and gamma exists. model_inervention_expected

yayami3 avatar Jan 09 '24 13:01 yayami3

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.

fehiepsi avatar Jan 12 '24 16:01 fehiepsi

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.

yayami3 avatar Jan 16 '24 13:01 yayami3

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 avatar Jan 16 '24 17:01 fehiepsi

@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.

yayami3 avatar Jan 17 '24 13:01 yayami3

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.

fehiepsi avatar Jul 01 '24 00:07 fehiepsi