- Notifications
You must be signed in to change notification settings - Fork 198
Probability Distribution and Statistical Functions -- Uniform Distribution Module #272
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
Changes from 1 commit
edf8e54 322a3a8 4b336de 1664d42 dbb7de7 d3214fc 7d30492 0d3b59f 3987d62 98e3d48 b714194 49f9d89 d900cfd 2a650ed d4f701c 2a495ab 8e95e05 3d8e3e6 0629dbf b076c2d b58681c c2f1108 be19e11 ad6e40a 6fceac9 f00cd15 afb881e 8abb168 a16faec 157dba8 d7643cb 5651f5e 5afcba5 4cb0041 91c1ad4 aed0d77 4d7fb2d 20a3403 fce3d03 a39f5ef deb318a 96c921b ea14a81 d791afe 8cbbb51 460fdd5 e678818 d25097f 800d94e c6c5fa7 3a6f26f c379711 a5735ea bd66d42 3e89cdc a1543f2 c9e67e7 6abd81c af74dac fbd5f52 d9709df da7d277 349d0eb ffdb937 c7cf916 ba70104 e155e1e 2e810fc 0beff2a ce9c467 9691008 1513e84 5600315 c74589e 6bd7b2a bc93073 652094a 310c047 b026328 80b1cc7 48ba194 e9433cf baa9495 8040c3e 0ebfbde b0fe2c4 b148167 bb7118e b184825 a47ea79 0073be2 f8e1f76 f40c023 63a015e 6c7a3c6 d39097c e4a405a 03d5a81 cdfb497 e62f241 cf408bc 376bdc1 b6e0c36 9bebab0 af7e831 09a172c a55a671 5dbad35 8b9d16d 06174e4 0a00a03 193a9c5 93acc2c c2dac0e 231bd35 b9091e0 8214d74 6e3aca5 ed25e21 cfbee66 58394f1 cc29ce8 cd061f6 230c1c6 635cc7b 50d04e2 8eac7f1 7327142 ad180de 14a7e09 5c2e5da ad23f64 d963f09 d5cba5b 669fc99 464fa31 bc8a053 c70b920 75a66b2 61718ab 9849dcd 5d33ba7 5cebe32 d2117de 615ac95 e728ae0 fecbedf 4b2152d d21a17c aaeb17a 51e234c 3611e59 922ad3c 1fa3094 bf126c0 d0f62b2 54bcd22 1fac091 a2a993d c331d67 1152f04 8186ead 939fd1a 2469f52 a4330cc b8a96b5 6379458 3988da1 1c46c10 d9dcbe0 a2bf0ed 7bdfc05 65ec424 bd6c97c edf6ac8 916f69a 870fd3b c57e7fc ae1c3f9 a9eee6b a904337 884623b a435b04 b877660 7a650f1 e11454d b13a48e cc4d3f2 3bc615b 22a6023 39e991b 227e520 bcd876c File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| | @@ -134,7 +134,7 @@ Module stdlib_stats_distribution_uniform | |||
| ! Uniformly distributed float in [0,1] | ||||
| ! Based on the paper by Frederic Goualard, "Generating Random Floating- | ||||
| ! Point Numbers By Dividing Integers: a Case Study", Proceedings of | ||||
| ! ICCS 2020, June 20202, Amsterdam, Netherlands | ||||
| ! ICCS 2020, June 2020, Amsterdam, Netherlands | ||||
| ! | ||||
| ${t1}$ :: res | ||||
| integer(int64) :: tmp | ||||
| | @@ -201,7 +201,7 @@ Module stdlib_stats_distribution_uniform | |||
| tr = real(scale) * r1 | ||||
| ti = aimag(scale) * r2 | ||||
| endif | ||||
| res = cmplx(tr, ti) | ||||
| res = cmplx(tr, ti, kind=${k1}$) | ||||
| return | ||||
| ||||
| return |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that Goualard mentions dividing integers by a Mersenne number to make a floating-point number to make a point that doing so can lead to non-uniformity issues, and not necessarily to show that libraries should generate random floating-point numbers this way. He makes the same point with dividing integers by a power of 2.
Also, there are ways to implement uniform floating-point number generation that covers all numbers the
realtype covers in [0, 1], but in general they are far from trivial which is why I don't demand it here. Examples include the Rademacher Floating-Point Library by @christophe-conrads as well as an algorithm I give.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite understand your point. Yes, dividing Mersenne integer leads to non-uniformity. Multiplying the inverse of the same number reduces the issue significantly.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is indeed to reduce non-uniformity, especially since this code is intended to form part of the standard library and thus be used by thousands of applications with different requirements, and while some of them may not care about the statistical quality of pseudorandom numbers, others may. In this sense, of the methods that involve multiplying or dividing an integer by a constant to create a binary64, the "best" one is to multiply a binary64 integer in [1, 2^53) (which is representable in binary64) by the binary64 constant 1/2^53. This is "better" than multiplying an integer by a Mersenne number or its inverse, because it "better" ensures the binary64 values are evenly spaced in [0, 1] as the result of the multiplication is representable in binary64. This difference is illustrated if we multiply 5201 by either 1/2^53 or 1/2^53-1 (in exact rational arithmetic), then convert the result to binary64 and back. (Notice that I put "best" and "better" in quotes here, in part because, in my opinion, floating-point random numbers should be avoided whenever random integers or random rational numbers suffice.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on Goualard paper, the best one is a binary64 integer in [1, 2^53) multiplying a float of 1/(2^53-1) as shown in Fig 7. in the paper. This is exactly what I implemented in the module. Dividing binary64 integer by 2^53 leads to more non-uniformity as GNU Fortran 9.2.0 does.