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

sampling from Dirichlet produces NaN and Inf at extreme alpha #1702

Open
clolesen opened this issue Mar 28, 2023 · 0 comments · May be fixed by #1886
Open

sampling from Dirichlet produces NaN and Inf at extreme alpha #1702

clolesen opened this issue Mar 28, 2023 · 0 comments · May be fixed by #1886

Comments

@clolesen
Copy link

In my code a random process generates alpha vectors for Dirichlet distributions and on rare occasions these can have extreme values. When sampling with an alpha where all values are extremely low the rand() function returns an array of NaN, sometimes with an Inf in there. Here is an example:

rand(Dirichlet([8e-5, 1e-5, 2e-5]))

At slightly less extreme values it produce NaN arrays less frequently, but still sometimes:

rand(Dirichlet([8e-4, 1e-4, 2e-4]))

It seem to only happen when all values are low.

I don't know if this is really a bug. There is no practical difference between these examples and using less extreme values that works (they are so extreme they will always produce certainty in one category). So it is easy to make a work around to makes my code run. However, I thought report it anyway as it might highlight a deeper, less noticeable problem?

I have also experienced it producing a vector where the values doesn't sum to 1. So much that the Categorical distribution throws and error saying that it is not a probability vector. But I failed to make a reproducible example (might be a bug of my own then?). Is this something there could be an explanation for?

quildtide added a commit to quildtide/Distributions.jl that referenced this issue Aug 16, 2024
quildtide added a commit to quildtide/Distributions.jl that referenced this issue Aug 16, 2024
@quildtide quildtide linked a pull request Aug 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant