Skip to content

Dirichlet.random shape problems #4060

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
brandonwillard opened this issue Aug 21, 2020 · 1 comment · Fixed by #4416
Closed

Dirichlet.random shape problems #4060

brandonwillard opened this issue Aug 21, 2020 · 1 comment · Fixed by #4416

Comments

@brandonwillard
Copy link
Contributor

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
@ColCarroll
Copy link
Member

Just as a sanity check, scipy has "correct" behavior. Not sure why distribution shape tests didn't catch...

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

Successfully merging a pull request may close this issue.

3 participants