Skip to content

Broken str representation for Kronecker Normal distribution #4240

Closed
@Sayam753

Description

@Sayam753

If you have questions about a specific use case, or you are not sure whether this is a bug or not, please post it to our discourse channel: https://discourse.pymc.io

Description of your problem

This issue popped out while I was in pdb debugger, figuring out the reason of failing test cases in #4207

Please provide a minimal, self-contained, and reproducible example.

>>> import numpy as np
>>> import pymc3 as pm
>>> K1 = np.array([[1., 0.5], [0.5, 2]])
>>> K2 = np.array([[1., 0.4, 0.2], [0.4, 2, 0.3], [0.2, 0.3, 1]])
>>> covs = [K1, K2]
>>> N = 6
>>> mu = np.zeros(N)
>>> with pm.Model() as model:
...     vals = pm.KroneckerNormal('vals', mu=mu, covs=covs, shape=N)
... 
>>> vals

Please provide the full traceback.

>>> vals
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sayam/.local/lib/python3.8/site-packages/theano/gof/graph.py", line 449, in __repr__
    to_print = [str(self)]
  File "/home/sayam/Desktop/pymc/pymc3/pymc3/model.py", line 83, in __str__
    return self._str_repr(formatting="plain", **kwargs)
  File "/home/sayam/Desktop/pymc/pymc3/pymc3/model.py", line 77, in _str_repr
    return self.distribution._str_repr(name=name, dist=dist, formatting=formatting)
  File "/home/sayam/Desktop/pymc/pymc3/pymc3/distributions/distribution.py", line 176, in _str_repr
    param_values = [
  File "/home/sayam/Desktop/pymc/pymc3/pymc3/distributions/distribution.py", line 177, in <listcomp>
    get_repr_for_variable(getattr(dist, x), formatting=formatting) for x in param_names
  File "/home/sayam/Desktop/pymc/pymc3/pymc3/util.py", line 131, in get_repr_for_variable
    name = variable.name if variable is not None else None
AttributeError: 'list' object has no attribute 'name'

Please provide any additional information below.

https://github.com/pymc-devs/pymc3/blob/ad63b94342260ca21d385f2539e243aaf62d26aa/pymc3/util.py#L130-L131

I imagine to use getattr for variable. Pinging @Spaak, @AlexAndorra to help here.

Versions and main components

  • PyMC3 Version: master
  • Theano Version: 1.0.11
  • Python Version: 3.8.6
  • Operating system: Ubuntu 18.04 LTS
  • How did you install PyMC3: (conda/pip) pip

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions