Skip to content

HalfFlat initval dimensionality is broken #4993

@michaelosthege

Description

@michaelosthege

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions