-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
When we create RVs via the the Distribution interface, they get some str_repr methods glued to them:
pymc/pymc/distributions/distribution.py
Lines 302 to 306 in 4acd98e
| # add in pretty-printing support | |
| rv_out.str_repr = types.MethodType(str_for_dist, rv_out) | |
| rv_out._repr_latex_ = types.MethodType( | |
| functools.partial(str_for_dist, formatting="latex"), rv_out | |
| ) |
The Model.str_repr then expects all named variables to have this method, which fails for automatically generated RVs such as those in automatic imputation
import numpy as np
import pymc as pm
with pm.Model() as m:
pm.Normal("x", observed=[np.nan, 0, 0])
m.str_repr() # Called automatically in a Jupyter environment for pretty-printingAttributeError: 'TensorVariable' object has no attribute 'str_repr'
It also which makes it annoying to replace / register variables manually:
x = pm.Normal.dist() # No `str_repr` attached
with pm.Model() as m:
m.register_rv(x, name="x")
m.str_repr() # Same errorSuggestion
Do not rely on the methods being attached for model.str_repr
Line 103 in fd5a6cc
| rv_reprs = [rv.str_repr(formatting=formatting, include_params=include_params) for rv in all_rv] |
Instead just use a dispatch base approach to pretty-print any model variables based on their Op types as discussed elsewhere.