Skip to content

HalfFlat initval dimensionality is broken #4993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
michaelosthege opened this issue Sep 15, 2021 · 3 comments
Closed

HalfFlat initval dimensionality is broken #4993

michaelosthege opened this issue Sep 15, 2021 · 3 comments

Comments

@michaelosthege
Copy link
Member

Description of your problem

Initial values for non-scalar HalfFlat (and probably Flat too) have a shape problem.

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

with pm.Model(coords={
    "city": np.array(["Paris", "Berlin", "Venice"], dtype=str),
}) as pmodel:
    pm.HalfFlat("hf_scalar")
    pm.HalfFlat("hf_shape", shape=(2,))
    pm.HalfFlat("hf_dims", dims=("city",))

Please provide the full traceback.

Complete error traceback
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-19-21fc589ae251> in <module>
      3 }) as pmodel:
      4     pm.HalfFlat("hf_scalar")
----> 5     pm.HalfFlat("hf_shape", shape=(2,))
      6     pm.HalfFlat("hf_dims", dims=("city",))

c:\users\osthege\repos\pymc3-v4\pymc3\distributions\distribution.py in __new__(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
    214         # Create the RV without dims information, because that's not something tracked at the Aesara level.
    215         # If necessary we'll later replicate to a different size implied by already known dims.
--> 216         rv_out = cls.dist(*args, rng=rng, **kwargs)
    217         ndim_actual = rv_out.ndim
    218         resize_shape = None

c:\users\osthege\repos\pymc3-v4\pymc3\distributions\continuous.py in dist(cls, size, **kwargs)
    429     def dist(cls, *, size=None, **kwargs):
    430         res = super().dist([], size=size, **kwargs)
--> 431         res.tag.test_value = np.full(size, floatX(1.0))
    432         return res
    433 

~\AppData\Local\Continuum\miniconda3\envs\pm3v4\lib\site-packages\aesara\graph\utils.py in __setattr__(self, attr, obj)
    265 
    266         if getattr(self, "attr", None) == attr:
--> 267             obj = self.attr_filter(obj)
    268 
    269         return object.__setattr__(self, attr, obj)

~\AppData\Local\Continuum\miniconda3\envs\pm3v4\lib\site-packages\aesara\tensor\type.py in filter(self, data, strict, allow_downcast)
    201 
    202         if self.ndim != data.ndim:
--> 203             raise TypeError(
    204                 f"Wrong number of dimensions: expected {self.ndim},"
    205                 f" got {data.ndim} with shape {data.shape}."

TypeError: Wrong number of dimensions: expected 1, got 0 with shape ().

Versions and main components

  • PyMC3 Version: main
@michaelosthege
Copy link
Member Author

michaelosthege commented Sep 25, 2021

Wasn't actually closed by that commit above. (But a fix is just around the corner with the big initval framework PR.)

@ricardoV94
Copy link
Member

@michaelosthege can we close this? Are we still missing a test?

@michaelosthege
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants