You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Uniform<f32/f64> should honor high/low limits #476
We should require that all Uniform distributions stick to the high/low limits, even in the face of rounding issues. Users are likely to see unexpected and hard-to-reproduce bugs if the returned value on rare occasions will be outside of the specified limits.
One example that I ran into was while implementing choose_weighted for dhardy#82. If the generated number can be slightly higher than high, that means that we risk iterating through the whole item-set without selecting any item to return.
The simplest approach is to simply check the generated value against high/low and loop if it doesn't fit withing the desired boundaries. However that runs into problem when scale rounds to infinity, since then we'll just loop forever.
Probably either rejection sampling or clamping will be needed...
I'd rather see a complete solution for one particular problem (e.g. choose_weighted), and then discuss whether to adjust Uniform sampling. Use guard functions for the sampling if necessary.
I'd rather see a complete solution for one particular problem (e.g. choose_weighted), and then discuss whether to adjust Uniform sampling.
Just wanted to write the same. Good that you thought about this corner case! But I can see other users complaining about the performance drop in gen_range, for a reason they don't cure much about. Maybe it is better to do the rejection sampling outside of gen_range?
@dhardy It can be a simple function, but what do you think of some method to make rejection sampling extra simple (i.e. that allows users to not write the loop)? Not thought it through though...
Activity
Ensure that Uniform<f32/f64> and gen_range<f32/f64> always return val…
dhardy commentedon May 25, 2018
Probably either rejection sampling or clamping will be needed...
I'd rather see a complete solution for one particular problem (e.g.
choose_weighted), and then discuss whether to adjustUniformsampling. Use guard functions for the sampling if necessary.pitdicker commentedon May 25, 2018
Just wanted to write the same. Good that you thought about this corner case! But I can see other users complaining about the performance drop in
gen_range, for a reason they don't cure much about. Maybe it is better to do the rejection sampling outside ofgen_range?@dhardy It can be a simple function, but what do you think of some method to make rejection sampling extra simple (i.e. that allows users to not write the loop)? Not thought it through though...
dhardy commentedon May 25, 2018
So something like
Uniform::new(low, high).sample_strict(&mut rng)? I suppose that could work.pitdicker commentedon May 25, 2018
I was thinking more in the direction of:
Hmmm, doesn't look great. Maybe some iterator adapter:
Also ugly. And does the same as:
dhardy commentedon May 25, 2018
Yes, a new method on
Uniformwas the only way I could think of not having to specify the limits twice.Not sure if it's worth it, but it could be an unobtrusive layer on top of the current
sampleat least.Ensure that Uniform<f32/f64> and gen_range<f32/f64> always return val…
Ensure that Uniform<f32/f64> and gen_range<f32/f64> always return val…
Ensure that Uniform<f32/f64> and gen_range<f32/f64> always return val…
Make Uniform<f32/f64> and gen_range<f32/f64> honor limits strictly. R…
Make Uniform<f32/f64> and gen_range<f32/f64> honor limits strictly. R…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Make Uniform and gen_range honor limits strictly for floating point t…
Merge pull request #477 from sicking/limit_inexact_float
Ensure that Uniform<f32/f64> and gen_range<f32/f64> always return val…