question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dirichlet doesn't accept its own random variates as input to pdf

See original GitHub issue

In [1]: import scipy.stats as ss

In [2]: d = ss.dirichlet([1,3,4])

In [3]: d.pdf(d.rvs())
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-a6f3762e83cf> in <module>()
----> 1 d.pdf(d.rvs())

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/scipy/stats/_multivariate.py in pdf(self, x)
   1365
   1366     def pdf(self, x):
-> 1367         return self._dist.pdf(x, self.alpha)
   1368
   1369     def mean(self):

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/scipy/stats/_multivariate.py in pdf(self, x, alpha)
   1260         """
   1261         alpha = _dirichlet_check_parameters(alpha)
-> 1262         x = _dirichlet_check_input(alpha, x)
   1263
   1264         out = np.exp(self._logpdf(x, alpha))

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/scipy/stats/_multivariate.py in _dirichlet_check_input(alpha, x)
   1079                          "of entries as, or one entry fewer than, "
   1080                          "parameter vector 'a', but alpha.shape = %s "
-> 1081                          "and x.shape = %s." % (alpha.shape, x.shape))
   1082
   1083     if x.shape[0] != alpha.shape[0]:

ValueError: Vector 'x' must have either the same number of entries as, or one entry fewer than, parameter vector 'a', but alpha.shape = (3,) and x.shape = (1, 3).

In [4]: n = ss.norm()

In [5]: n.pdf(n.rvs())
Out[5]: 0.16964393208168185

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:28 (28 by maintainers)

github_iconTop GitHub Comments

4reactions
mdhabercommented, May 25, 2022

Update: it’s actually been six years since gh-6005, and Friday would be the anniversary. It would be fun to fix it that day : )

2reactions
tirthasheshpatelcommented, May 25, 2022

Wouldn’t it make sense to repair this bug before introducing another distribution that would have to be deprecated?

I think gh-7689 is clearly a bug and deprecation should not be necessary in theory. Although, it also has been the behavior of many methods of several multivariate distributions for a long time so there might be genuine concerns of backward-compatibility.

@mdhaber @tupui @Kai-Striega @chrisb83 Should we consider this a bug and fix it without maintaining back-compat or should we first deprecate and then change the behavior?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Help writing Dirichlet (multidimensional Beta) PDF correctly
Can someone please help me correct this Dirichlet distribution over θ with parameter X? A solution that works in the general case of...
Read more >
Dirichlet Distribution - an overview | ScienceDirect Topics
Consider an experiment with possible outcomes , having respective probabilities , , and suppose we want to assume a probability distribution on the...
Read more >
Input uncertainty in stochastic simulations in the presence of ...
This paper considers stochastic simulations with correlated input random variables having. NORmal-To-Anything (NORTA) distributions. We assume ...
Read more >
Matrix-Variate Dirichlet Process Priors with Applications
Abstract. In this paper we propose a matrix-variate Dirichlet process (MATDP) for modeling the joint prior of a set of random matrices. Our...
Read more >
The intuition behind Latent Dirichlet Allocation (LDA) - Medium
It's a univariate distribution of random variables that belong to the range 0 ... of distributions over the latent variables with its own...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found