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

Infinite loop in truncated normal distribution #1712

Open
danielmatz opened this issue Apr 28, 2023 · 2 comments · May be fixed by #1721
Open

Infinite loop in truncated normal distribution #1712

danielmatz opened this issue Apr 28, 2023 · 2 comments · May be fixed by #1721

Comments

@danielmatz
Copy link

Using Distributions v0.25.87, the following results in an infinite loop:

julia> d = Normal(204.764679086758, 0.0)
Normal{Float64}=204.764679086758, σ=0.0)

julia> rand(d)
204.764679086758

julia> d2 = truncated(d, 204.764679086758, 204.764679086758)
Truncated(Normal{Float64}=204.764679086758, σ=0.0); lower=204.764679086758, upper=204.764679086758)

julia> rand(d2)
# hangs

Perhaps setting standard deviation to 0.0 is an odd thing to do, but I was expecting it to just return 204.764679086758 on all calls to rand.

@ararslan
Copy link
Member

It seems there are two cases where 0 standard deviation is problematic:

  1. the truncation points are equal
  2. they're unequal but the mean does not lie between them

If the truncation points are unequal and the mean does lie between them, a standard deviation of 0 work just fine and rand always produces the mean. I think in your case, where the mean and both truncation points are all equal, rand should indeed produce the mean. If the mean lies outside of the truncated region and the standard deviation is 0, since no value within the region has nonzero probability, the result should probably be NaN.

@quildtide
Copy link
Contributor

quildtide commented Dec 21, 2023

Duplicate with #1264 in terms of underlying cause.

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.

3 participants