-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Variable selection for graphviz visualization via kwarg #5634
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
Variable selection for graphviz visualization via kwarg #5634
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5634 +/- ##
==========================================
+ Coverage 89.28% 89.36% +0.07%
==========================================
Files 74 74
Lines 13824 13804 -20
==========================================
- Hits 12343 12336 -7
+ Misses 1481 1468 -13
|
@michaelosthege Can you have a look at these changes on a model or two? Happy to hear comments. It seems to work on my model in this notebook but we can't see the figures on GitHub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going into the right direction.
Here's a minimal example that unveils two problems:
- Selecting nodes causes some of them to change formatting
- Nodes of observed data have an inverted dependency - this could be tricky.. One can get the desired result by selecting the observed RV, but because of the reversed arrow direction it's counterintuitive.
import pymc as pm
from IPython.display import display
with pm.Model() as pmodel2:
a = pm.Normal("a")
b = pm.Normal("b")
pm.Normal("c", a * b)
intermediate = pm.Deterministic("intermediate", a + b)
pred = pm.Deterministic("pred", intermediate * 3)
obs = pm.ConstantData("obs", 1.75)
pm.Normal("L", mu=1 + 0.5 * pred, observed=obs)
display(pm.model_to_graphviz(pmodel2))
display(pm.model_to_graphviz(pmodel2, selected_vars=["L"]))
display(pm.model_to_graphviz(pmodel2, selected_vars=["obs"]))
Thanks for the pointers and example. Will look into it. Do you know approximately when the code has been written? My guess is that |
You can check the git blame: https://github.com/pymc-devs/pymc/blame/main/pymc/model_graph.py But generally the code works. Also for my biggest model all variables are shown |
I believe that the plots now display desired graphs in your example above. Can you verify? I am using |
96c5f98
to
5570808
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the plots now display desired graphs in your example above. Can you verify?
Yes, it's looking good for my big model too! Tomorrow morning I can then finally plot my model and print it on an A3 sheet of paper for the meeting on thursday 😃 So thank you for getting it to work 💯
Maybe a bit unexpected that selecting "L" also shows "obs", but it's probably a good idea to do that. It's a feature.
I added some type hint suggestions, and renaming of variables. My suggestions are incomplete, but I think you get the idea.
You can add tests to https://github.com/pymc-devs/pymc/blob/main/pymc/tests/test_model_graph.py. These tests work by comparing the dict representation of the grpah/plates with the expected outcome.
Thanks so much for the suggestions! I'll address them one by one. Just wanted you to have the figures for your meeting and work on polishing the code more slowly |
bbc5e33
to
a706229
Compare
Reminder for myself to add a test |
The solution currently is very ad-hoc as I do not understand
Things not sure if I should look into more
@michaelosthege can I get your input? |
c898048
to
28d7f2e
Compare
Quick comment that I did not forget about this PR, just busy with many other things. There's ongoing work with |
f183725
to
598a2c5
Compare
I'm revisiting this PR and would like to push it to the finish line after a long hiatus 😅 In summary, this PR:
I'm hoping that all tests pass. Happy to hear any comments about this progress as it would be worthwhile to address issues #5616 and #5766 shortly afterwards. I imagine that I should add type hints to the methods? |
Type hints are always good 👍 But also make sure to explain the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larryshamalama we'll only need that docstinrg, then this is good to go!
Sounds good! I'll fix this later today on the train 😅 |
I only added the docstring to On another note, I refactored a lot of the code since, with |
4c4104a
to
edf40bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have a few typing changes, otherwise this looks great 👍
I'll apply my suggestions & fix the pre-commit if needed... ⏳
/pre-commit-run |
Thanks @larryshamalama ! I'm sure this will prove to be a very useful feature for the still underappreciated |
Thanks to you for your suggestions too :) |
Fixes #5527. Some elements are hackish and currently need more work.
var_names
as kwargvar_names
class instance by_all_var_names