Distributions.jl icon indicating copy to clipboard operation
Distributions.jl copied to clipboard

Inconsistent behaviour of `truncate` for discrete distributions

Open lcontento opened this issue 2 years ago • 1 comments

When truncating a Geometric distributions, rand will return different types depending on the bounds chosen. For example, values sampled from truncated(Geometric(0.6); lower = 2) are floats, while values sampled from truncated(Geometric(0.6); upper = 4) are integers. I guess this is due to https://github.com/JuliaStats/Distributions.jl/blob/7e232ca86c56c4b2e1e7a44b16aa23c26668af3d/src/truncate.jl#L211-L229 using the float-returning quantile / invlogcdf in special cases.

lcontento avatar Nov 08 '23 10:11 lcontento

I think the problem are actually quantile and invlogcdf here. For Geometric they should always return an Int. For other distributions (and in particular discrete distributions) typically we ensure that the return type of quantile etc. and the type of the variates match. For instance, for discrete distributions where such calculations are performed with StatsFuns/Rmath we explicitly convert the result to Int.

devmotion avatar Nov 23 '23 16:11 devmotion