AttributeError: 'MvGaussianRandomWalk' object has no attribute 'mu'

I get the error in the title when I try to plot with with pm.model_to_graphviz a model that cointains a distribution pm.MvGaussianRandomWalk. For example, if I run:

import numpy as np
import pymc3 as pm

shape=(3,2)
chol=np.array([[1,0],[1,1]])
mu=np.zeros(2)

with pm.Model() as model:
    RW = pm.MvGaussianRandomWalk("RW", mu=mu, chol=chol, shape=shape)
    
pm.model_to_graphviz(model)

I get the AttributeError:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-137-c15b2a78f541> in <module>
      9     RW = pm.MvGaussianRandomWalk("RW", mu=mu, chol=chol, shape=shape)
     10 
---> 11 pm.model_to_graphviz(model)

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/model_graph.py in model_to_graphviz(model, formatting)
    241         raise ValueError(f"Unsupported formatting for graph nodes: '{formatting}'. See docstring.")
    242     model = pm.modelcontext(model)
--> 243     return ModelGraph(model).make_graph(formatting=formatting)

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/model_graph.py in make_graph(self, formatting)
    207                 with graph.subgraph(name="cluster" + label) as sub:
    208                     for var_name in var_names:
--> 209                         self._make_node(var_name, sub, formatting=formatting)
    210                     # plate label goes bottom right
    211                     sub.attr(label=label, labeljust="r", labelloc="b", style="rounded")

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/model_graph.py in _make_node(self, var_name, graph, formatting)
    148             label = f"{var_name}\n~\nData"
    149         else:
--> 150             label = v._str_repr(formatting=formatting).replace(" ~ ", "\n~\n")
    151 
    152         graph.node(var_name.replace(":", "&"), label, **attrs)

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/model.py in _str_repr(self, name, dist, formatting)
     78         if dist is None and hasattr(self, "distribution"):
     79             dist = self.distribution
---> 80         return self.distribution._str_repr(name=name, dist=dist, formatting=formatting)
     81 
     82     def _repr_latex_(self, *, formatting="latex_with_params", **kwargs):

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/distributions/distribution.py in _str_repr(self, name, dist, formatting)
    211 
    212         param_names = self._distr_parameters_for_repr()
--> 213         param_values = [
    214             get_repr_for_variable(getattr(dist, x), formatting=formatting) for x in param_names
    215         ]

~/miniconda3/envs/pymc/lib/python3.9/site-packages/pymc3/distributions/distribution.py in <listcomp>(.0)
    212         param_names = self._distr_parameters_for_repr()
    213         param_values = [
--> 214             get_repr_for_variable(getattr(dist, x), formatting=formatting) for x in param_names
    215         ]
    216 

AttributeError: 'MvGaussianRandomWalk' object has no attribute 'mu'

Package Versions:

Python    : 3.9.5
pymc3     : 3.11.2
theano    : 1.0.5
1 Like

I observed the same behaviour, the model compiles and samples but the graph builder is not able to find the mu attribute.

I suspect the reason lies here , MvGaussianRandomWalk parses mu (along with other arguments) as an innovArgs attribute which are then passes to a MvNormal. Effectively the mu argument does not exist as an attribute of the distribution.

1 Like

Looks like there have been some similar issues raised in the past. (e.g., this one). If someone wants to submit an issue, that would be great.

2 Likes

Thanks I will.