Skip to content
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

DOC: fix simplex math for scipy.stats.dirichlet documentation #12435

Merged
merged 2 commits into from
Jun 29, 2020

Conversation

AtsushiSakai
Copy link
Member

Reference issue

fix #12415

What does this implement/fix?

fixed simplex math for scipy.stats.dirichlet documentation based on https://en.wikipedia.org/wiki/Dirichlet_distribution.
And added a comment about error raising.

@AtsushiSakai AtsushiSakai added Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.stats labels Jun 27, 2020
@AtsushiSakai
Copy link
Member Author

I confirmed the current implementation satisfies the new simplex math.

>>> from scipy.stats import dirichlet
>>> import numpy as np
>>> quantiles = np.array([0.2, 0.2, 0.6])
>>> alpha = np.array([0.4, 5, 15])  
>>> dirichlet.pdf(quantiles, alpha)
0.2843831684937255
>>> quantiles = np.array([0.2, 0.2, 0.5])
>>> dirichlet.pdf(quantiles, alpha)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 1483, in pdf
    x = _dirichlet_check_input(alpha, x)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 1286, in _dirichlet_check_input
    raise ValueError("The input vector 'x' must lie within the normal "
ValueError: The input vector 'x' must lie within the normal simplex. but np.sum(x, 0) = 0.9.
>>> quantiles = np.array([0.6, -0.2, 0.6])
>>> dirichlet.pdf(quantiles, alpha)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 1483, in pdf
    x = _dirichlet_check_input(alpha, x)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scipy/stats/_multivariate.py", line 1268, in _dirichlet_check_input
    raise ValueError("Each entry in 'x' must be greater than or equal "
ValueError: Each entry in 'x' must be greater than or equal to zero.

@AtsushiSakai AtsushiSakai changed the title Doc: fix simplex math for scipy.stats.dirichlet documentation DOC: fix simplex math for scipy.stats.dirichlet documentation Jun 29, 2020
Copy link
Member

@WarrenWeckesser WarrenWeckesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested a small change to fix how the LaTeX is rendered.

scipy/stats/_multivariate.py Outdated Show resolved Hide resolved
Co-authored-by: Warren Weckesser <warren.weckesser@gmail.com>
Copy link
Member

@WarrenWeckesser WarrenWeckesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@WarrenWeckesser WarrenWeckesser merged commit 5f69fc7 into scipy:master Jun 29, 2020
@WarrenWeckesser
Copy link
Member

Thanks @AtsushiSakai, merged.

@tylerjereddy tylerjereddy added this to the 1.6.0 milestone Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.stats
Projects
None yet
Development

Successfully merging this pull request may close these issues.

scipy.stats.dirichlet documentation issue
3 participants