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

model_to_graphviz does not draw edges to interaction nodes #3413

Closed
jvparidon opened this issue Mar 19, 2019 · 3 comments
Closed

model_to_graphviz does not draw edges to interaction nodes #3413

jvparidon opened this issue Mar 19, 2019 · 3 comments

Comments

@jvparidon
Copy link

jvparidon commented Mar 19, 2019

Problem description

model_to_graphviz is a great visualization tool, but it currently does not draw edges to interaction terms. Nodes with names that contain a colon are not connected to the model graph because graphviz does not understand how to draw the edges.

Calls to graphviz from PyMC3 are translated into DOT and that language standard treats colons as a special character. When the graph is drawn and the instructions for drawing the edges are parsed, having a colon in one of the node names causes graphviz to look for a non-existent node to connect the edge to. This leads to missing edges in the graph and graphviz will issue a warning, but neither graphviz nor PyMC3 throws an exception.

Minimal working example

import numpy as np
import pandas as pd
import pymc3 as pm

# toy data
df = pd.DataFrame({
    'y': np.random.random(10),
    'x1': np.random.random(10),
    'x2': np.random.random(10)
})

with pm.Model() as linear_model:
    pm.glm.GLM.from_formula('y ~ x1 * x2', data=df)
    pm.model_to_graphviz(linear_model).view()

Versions and main components

  • PyMC3 Version: 3.6
  • Theano Version: 1.0.4
  • Python Version: 3.7.1
  • Operating system: macOS 10.14.1
  • How did you install PyMC3: pip
@lucianopaz
Copy link
Contributor

lucianopaz commented Mar 19, 2019

Thanks for reporting thid @jvparidon. It seems like this should be easy to fix by inserting the names in quotes, or somehow escaping the colon in the names. Would you be interested in trying to address this with a PR?

@jvparidon
Copy link
Author

Unfortunately, graphviz appears to parse colons in node names even if the names are in quotes, this is a known issue. The recommended workaround is to just remove colons from the node names but leave them in the node labels which will be drawn in the graph.
A string replace in the node name to replace colons with some other character before passing them to graphviz does indeed work, and seems like the easiest fix to me. I'll submit a PR.

@junpenglao
Copy link
Member

Closed in #3414

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

No branches or pull requests

3 participants