pymc.model_table#
- pymc.model_table(model, *, split_groups=True, truncate_deterministic=None, parameter_count=True)[source]#
Create a rich table with a summary of the model’s variables and their expressions.
- Parameters:
- model
Model The PyMC model to summarize.
- split_groupsbool
If True, each group of variables (data, free_RVs, deterministics, potentials, observed_RVs) will be separated by a section.
- truncate_deterministic
int|None If not None, truncate the expression of deterministic variables that go beyond this length.
- parameter_countbool
If True, add a row with the total number of parameters in the model.
- model
- Returns:
TableA rich table with the model’s variables, their expressions and dims.
Examples
import numpy as np import pymc as pm from pymc import model_table coords = {"subject": range(20), "param": ["a", "b"]} with pm.Model(coords=coords) as m: x = pm.Data("x", np.random.normal(size=(20, 2)), dims=("subject", "param")) y = pm.Data("y", np.random.normal(size=(20,)), dims="subject") beta = pm.Normal("beta", mu=0, sigma=1, dims="param") mu = pm.Deterministic("mu", pm.math.dot(x, beta), dims="subject") sigma = pm.HalfNormal("sigma", sigma=1) y_obs = pm.Normal("y_obs", mu=mu, sigma=sigma, observed=y, dims="subject") table = model_table(m) table # Displays the following table in an interactive environment ''' Variable Expression Dimensions ───────────────────────────────────────────────────── x = Data subject[20] × param[2] y = Data subject[20] beta ~ Normal(0, 1) param[2] sigma ~ HalfNormal(0, 1) Parameter count = 3 mu = f(beta) subject[20] y_obs ~ Normal(mu, sigma) subject[20] '''
Output can be explicitly rendered in a rich console or exported to text, html or svg.
from rich.console import Console console = Console(record=True) console.print(table) text_export = console.export_text() html_export = console.export_html() svg_export = console.export_svg()