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

Merged
merged 1 commit into from
Jan 17, 2025

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.

@wiep
Copy link
Contributor Author

wiep commented Jan 16, 2025

In the current implementation, the legend is always shown for all entries. In the first plot the legend includes the black arrow even though it is not used in the plot.

@jobrachem
Copy link
Contributor

👍

@jobrachem
Copy link
Contributor

From my point of view, the PR can be merged @wiep.

@wiep
Copy link
Contributor Author

wiep commented Jan 17, 2025

great.

regarding the legend, it could be improved so that things that are not needed are removed and maybe use a round symbol or star and not a line to indicate the colors of strong and weak.

@wiep wiep merged commit f5691a2 into main Jan 17, 2025
4 checks passed
@wiep wiep deleted the plot-var-calc-dist branch January 17, 2025 15:08
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