liesel-devs / liesel

A probabilistic programming framework
https://liesel-project.org
MIT License
40 stars 2 forks source link

Create a visual distinction for data flow into Calculators and Distributions #76

Closed GianmarcoCallegher closed 1 year ago

jobrachem commented 1 year ago

I would like to see what the result looks like ;)

GianmarcoCallegher commented 1 year ago
import liesel.model as lsl
import tensorflow_probability.substrates.jax.distributions as tfd
import jax.numpy as jnp

n0 = lsl.Param(1.0, None, 'n0')
n1 = lsl.Var(2.0, None, 'n1')
n2 = lsl.Var(lsl.Calc(jnp.exp, n1), None, 'n2')

n0.dist_node = lsl.Dist(tfd.HalfNormal, scale=n2)

gb = lsl.GraphBuilder()
gb.add(n0, n1, n2)
model = gb.build_model()

lsl.plot_vars(model)

Figure_1

It can be something like that. I'm not a huge fan of the solution.

Do we want to do that only for plot_vars?

jobrachem commented 1 year ago

I'm not sure whether I correctly understand what the purpose is. Is this interpretation correct?

Arrows that represent input to a variable's distribution are colored in light grey now, to create a visual distinction from arrows that represent input to a variable's calculator. The latter are colored in black, like they used to be.

GianmarcoCallegher commented 1 year ago

I'm not sure whether I correctly understand what the purpose is. Is this interpretation correct?

Arrows that represent input to a variable's distribution are colored in light grey now, to create a visual distinction from arrows that represent input to a variable's calculator. The latter are colored in black, like they used to be.

Yes

jobrachem commented 1 year ago

Thanks! Maybe then a legend entry for both cases would be nice, something like "black: Used in value", "grey: Used in distribution". What do you think?

GianmarcoCallegher commented 1 year ago

Thanks! Maybe then a legend entry for both cases would be nice, something like "black: Used in value", "grey: Used in distribution". What do you think?

Sure

GianmarcoCallegher commented 1 year ago

You can check now

jobrachem commented 1 year ago

image

I like it. One additional question: Why do you write "Used in value or calculator"? Can an input node be used in another node's value without the use of a calculator?

GianmarcoCallegher commented 1 year ago

image

I like it. One additional question: Why do you write "Used in value or calculator"? Can an input node be used in another node's value without the use of a calculator?

You are right, it's redundant. I fixed it