Skip to content

Commit 6f051ea

Browse files
Model graphviz (#5118)
* Adding an example for model to graphviz * Replacing with * pre commit message * pre commit correction Co-authored-by: Sev <[email protected]>
1 parent f87b8b2 commit 6f051ea

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

docs/source/api/model_graph.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ Graphing Models
44
.. currentmodule:: pymc.model_graph
55
.. automodule:: pymc.model_graph
66
:members:
7+
8+
.. image:: ../images/model_to_graphviz.png
9+
:width: 1000px
31.6 KB
Loading

pymc/model_graph.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,31 @@ def model_to_graphviz(model=None, *, formatting: str = "plain"):
233233
The model to plot. Not required when called from inside a modelcontext.
234234
formatting : str
235235
one of { "plain" }
236+
237+
Examples
238+
--------
239+
How to plot the graph of the model.
240+
241+
.. code-block:: python
242+
243+
import numpy as np
244+
from pymc import HalfCauchy, Model, Normal, model_to_graphviz
245+
246+
J = 8
247+
y = np.array([28, 8, -3, 7, -1, 1, 18, 12])
248+
sigma = np.array([15, 10, 16, 11, 9, 11, 10, 18])
249+
250+
with Model() as schools:
251+
252+
eta = Normal("eta", 0, 1, shape=J)
253+
mu = Normal("mu", 0, sigma=1e6)
254+
tau = HalfCauchy("tau", 25)
255+
256+
theta = mu + tau * eta
257+
258+
obs = Normal("obs", theta, sigma=sigma, observed=y)
259+
260+
model_to_graphviz(schools)
236261
"""
237262
if not "plain" in formatting:
238263
raise ValueError(f"Unsupported formatting for graph nodes: '{formatting}'. See docstring.")

0 commit comments

Comments
 (0)