pyro icon indicating copy to clipboard operation
pyro copied to clipboard

Render functions of random variables

Open Eric-Bradford opened this issue 2 years ago • 3 comments

I would like to show variables explicitly using "render_model" that are functions of other variables. I tried using "deterministic" or "Delta distribution" for this purpose, but this seems to not propagate like other distributions, e.g.

def model(data):
    m = pyro.sample("m", dist.Normal(0, 1))
    sd = pyro.sample("sd", dist.Delta(m**2))
    with pyro.plate("N", len(data)):
        pyro.sample("obs", dist.Normal(m, sd), obs=data)
data = torch.ones(10)
pyro.render_model(model, model_args=(data,))

image

If I define sd as a normal distribution it shows the connection between sd and obs correctly, but with "Delta" the connection is not shown. How can I define sd as a function of m that would show this connection?

Eric-Bradford avatar Sep 06 '22 14:09 Eric-Bradford

Hi @Eric-Bradford this looks like a bug to me, let me take a look at what might be causing it...

fritzo avatar Sep 06 '22 16:09 fritzo

Hi @fritzo, that would be great thanks!

Eric-Bradford avatar Sep 06 '22 17:09 Eric-Bradford

OK, this is not a bug, merely a historical design choice (pyro.infer.inspect originated as an inference tool that was concerned with only latent variables, hence it ignored deterministic dependencies). I've started sketching support for this feature in a branch but it's a little more complex than I expected due to low-level provenance tracking issues. Working on it...

fritzo avatar Sep 08 '22 13:09 fritzo

See also this forum discussion

fritzo avatar Jan 07 '23 13:01 fritzo

Have been any advances on this?

r3v1 avatar Jul 27 '23 20:07 r3v1

I believe there has been no progress, but @eb8680 was looking into it around 6 months ago.

fritzo avatar Jul 28 '23 14:07 fritzo

Is there any plan to implement this in the short time? I've tried patching it somehow but I got lost...

r3v1 avatar Aug 07 '23 16:08 r3v1

@r3v1 no, sorry, it's unlikely I/we will have the bandwidth to fix this ourselves any time soon. You're welcome to play around with the branch linked above and see if you can get it working yourself.

eb8680 avatar Aug 07 '23 17:08 eb8680

Thanks anyway. I tried but it was quite difficult for me to understand what is going on behind the scenes, I would take it more deeply if I had some documentation, by the way, do you have any resources about?

r3v1 avatar Aug 07 '23 19:08 r3v1