Skip to content

Inconsistent behavior of random for singleton RVs and draw sizes #4206

Closed
@lucianopaz

Description

@lucianopaz

Description of your problem

This issue summarizes two inconsistent behaviors of pymc3's random method. One happens for distributions that are declared with shape (1,). The other happens when a distribution's random method is called with size=1.

Singleton array distributions

>>> import pymc3 as pm
>>> pm.Normal.dist(0, 1, shape=1).random().shape
()
>>> pm.Normal.dist(0, 1, shape=1).random(size=10).shape
(10,)

These two calls should output shapes (1,) and (10, 1) respectively. The singleton distribution dimension is incorrectly reduced.

Random draws of a single value

>>> import pymc3 as pm
>>> pm.Normal.dist(0, 1).random(size=1).shape
()
>>> pm.Normal.dist(0, 1, shape=1).random(size=1).shape
()
>>> pm.Normal.dist(0, 1, shape=10).random(size=1).shape
(10,)

These calls should output (1,), (1, 1) and (1, 10) respectively, but the single draw is incorrectly reduced. In particular, this behavior should only happen when we supply size=None or size=().

Versions and main components

  • PyMC3 Version: 3.9.3
  • Theano Version: 1.0.5
  • Python Version: 3.7.6
  • Operating system: Ubuntu
  • How did you install PyMC3: (conda/pip) pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions