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

Add graphviz support for SymbolicRVs #6149

Closed

Conversation

larryshamalama
Copy link
Member

@larryshamalama larryshamalama commented Sep 26, 2022

Closes #5766.

Prior to this PR, symbolic distributions were labelled as "Deterministic" in the graph produced by Graphviz. The recent addition of symbolic RVs in #6072 allows pymc/model_graph.py to be adapted more easily. Here is an example of what is obtained using symbolic distributions such as pm.Mixture, pm.Censored, pm.ZeroInflatedPoisson.

with pm.Model() as model:
    psi = pm.Beta("psi", 1., 1.)
    mu_zip = pm.Gamma("mu_zip", 1., 1.)
    zip_var = pm.ZeroInflatedPoisson("zip", psi=psi, mu=mu_zip)
    
    mu_cens = pm.Normal("mu_cens", 0., 5.)
    sigma_cens = pm.HalfCauchy("sigma_cens", 2.5)
    normal_dist = pm.Normal.dist(mu=mu_cens, sigma=sigma_cens)
    censored_normal = pm.Censored("censored_normal", normal_dist, lower=-2., upper=2., observed=[0, 0.5, 1])
    
    mu_grw = pm.Normal("mu_grw", 0., 5.)
    sigma_grw = pm.HalfCauchy("sigma_grw", 2.5)
    pm.GaussianRandomWalk("grw", init_dist=pm.Normal.dist(mu_grw, sigma_grw), steps=10)
    
pm.model_to_graphviz(zip_model)

image

Tests in pymc/tests/test_model_graph.py checks that the arrows are pointing to and from the right variables and that the overall shape of the Graphviz Digraph is correct. Perhaps an additional check that the distribution names are correct can be added, because this is what this PR is about.

@codecov
Copy link

codecov bot commented Sep 26, 2022

Codecov Report

Merging #6149 (20cfc98) into main (ce89404) will increase coverage by 0.76%.
The diff coverage is 31.42%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6149      +/-   ##
==========================================
+ Coverage   88.84%   89.60%   +0.76%     
==========================================
  Files         101      101              
  Lines       22235    22264      +29     
==========================================
+ Hits        19755    19950     +195     
+ Misses       2480     2314     -166     
Impacted Files Coverage Δ
pymc/model_graph.py 59.50% <31.42%> (-19.45%) ⬇️
pymc/tests/distributions/test_timeseries.py 0.00% <0.00%> (-99.51%) ⬇️
pymc/tests/step_methods/hmc/test_quadpotential.py 0.00% <0.00%> (-95.82%) ⬇️
pymc/distributions/timeseries.py 28.46% <0.00%> (-66.00%) ⬇️
pymc/step_methods/hmc/quadpotential.py 73.76% <0.00%> (-6.94%) ⬇️
pymc/distributions/logprob.py 91.09% <0.00%> (-6.17%) ⬇️
pymc/distributions/shape_utils.py 97.42% <0.00%> (-0.43%) ⬇️
pymc/smc/smc.py 97.37% <0.00%> (+0.74%) ⬆️
pymc/distributions/censored.py 100.00% <0.00%> (+7.50%) ⬆️
... and 9 more

@larryshamalama larryshamalama force-pushed the symbolic-graphviz branch 5 times, most recently from 4444fd8 to 3bd3898 Compare October 3, 2022 16:46
@larryshamalama larryshamalama marked this pull request as draft October 9, 2022 18:00
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@larryshamalama
Copy link
Member Author

larryshamalama commented Oct 27, 2022

Closed in favor of a new PR that will use a dispatching approach

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.

ZeroInflatedPoisson and ZeroInflatedNegativeBinomial show up as Deterministic on graphviz
2 participants