Skip to content

Dirichlet.random shape problems #4060

Closed
@brandonwillard

Description

@brandonwillard

Dirichlet.random appears to have some shape issues.

import numpy as np

import pymc3 as pm


dir_dist = pm.Dirichlet.dist(np.r_[1, 1])

dir_dist.random()
[[0.47011506 0.52988494]
 [0.38131591 0.61868409]]

The output has too many dimensions.

Specifying size=1 only adds another dimension:

dir_dist.random(size=1)
[[[0.46690176 0.53309824]
  [0.01646167 0.98353833]]]

The output starts to look correct around here:

dir_dist.random(size=2)
[[0.18456125 0.81543875]
 [0.26424679 0.73575321]]

Larger values of size aren't any better:

dir_dist.random(size=3)
[[[0.46520733 0.53479267]
  [0.44132648 0.55867352]]

 [[0.69477003 0.30522997]
  [0.3173439  0.6826561 ]]

 [[0.82510178 0.17489822]
  [0.98854784 0.01145216]]]

If we set the shape explicitly, things seem to improve in the size=None case:

dir_dist = pm.Dirichlet.dist(np.r_[1, 1], shape=2)

dir_dist.random()
[0.01529536 0.98470464]

Unfortunately, things get weird when size == 2.

dir_dist.random(size=2)
[1. 1.]

Versions and main components

  • PyMC3 Version: 049187f
  • Theano Version: 1.0.4
  • Python Version: 3.6.4
  • Operating system: Ubuntu 20.04
  • How did you install PyMC3: pip

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