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

numpyro.render_model render unexpected graph with handler.do #1716

Open
yayami3 opened this issue Jan 9, 2024 · 5 comments
Open

numpyro.render_model render unexpected graph with handler.do #1716

yayami3 opened this issue Jan 9, 2024 · 5 comments

Comments

@yayami3
Copy link
Contributor

yayami3 commented Jan 9, 2024

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

@fehiepsi fehiepsi added the bug Something isn't working label Jan 12, 2024
@fehiepsi
Copy link
Member

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.

@yayami3
Copy link
Contributor Author

yayami3 commented Jan 16, 2024

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.

@fehiepsi
Copy link
Member

fehiepsi commented Jan 16, 2024

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?

@yayami3
Copy link
Contributor Author

yayami3 commented Jan 17, 2024

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

@fehiepsi
Copy link
Member

fehiepsi commented Jul 1, 2024

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 fehiepsi added discussion and removed bug Something isn't working labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants