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

Adds edge to plot_vars if input is used in value while var has distribution #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wiep
Copy link
Contributor

@wiep wiep commented Dec 10, 2024

Fixes #217.

Adds an edge if input is used in value of a node that has also a distribution. Introduces a red edge if input is used in value and dist node.

Changes the created by the code

import liesel.model as lsl
import jax.numpy as jnp
import tensorflow_probability.substrates.jax.distributions as tfd

# create a model
x = lsl.Var(jnp.arange(4).astype(float), name="x")
y = lsl.Var(jnp.arange(4).astype(float), name="y")
batch_index = lsl.Var(
    jnp.array([0, 1]),
    name="batch_index",
)
y_sel_dist = lsl.Dist(lambda x, idx: tfd.Normal(x[idx], 1.0), x, batch_index)
y_sel_val = lsl.Calc(lambda y, idx: y[idx], y, batch_index)
y_sel_val.value
y_sel = lsl.Var(
    y_sel_val,
    y_sel_dist,
    "y_sel",
)

model = lsl.GraphBuilder().add(y_sel_dist).build_model()
lsl.plot_vars(model)

from
old
to
new

Adds an edge if input is used in value of a node that has also a distribution.

Introduces a red edge if input is used in value and dist node.
@jobrachem
Copy link
Contributor

Is the additional legend entry always shown? I think it might be nice to show it only if there is such a case in the graph, because for many models it may not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plot_vars does not show value edges if var has dist
2 participants