-
Notifications
You must be signed in to change notification settings - Fork 2
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
Generators for floating point numbers #6
Comments
Provide all the good ones. And document the tradeoffs. And have the
defaults be the best quality ones. But with the combinators needed to
construct the alternatives.
…On Tue, Feb 18, 2020 at 2:49 PM Aleksey Khudyakov ***@***.***> wrote:
This question surfaced in discussion on PR #1
<#1> but it wasn't
discussed in any depth. Here is quote and links from @cartazio
<https://github.com/cartazio>:
There’s several gotchas with those algorithms for float and double.
The usual unit interval used in extent Haskell Libs is wrong.
See the commented out bit linked herein
https://github.com/haskell/random/blob/master/src/Data/Distribution/FloatingInterval.hs
@idontgetoutmuch <https://github.com/idontgetoutmuch>
Here's another implementation for getting random floating point numbers
https://github.com/mokus0/random-fu/blob/69a563a7b0cf444748e4b38a8bda7ada0b9acf14/random-source/src/Data/Random/Internal/Words.hs#L103
wordToFloat :: Word64 -> Float
wordToFloat x = (encodeFloat $! toInteger (x .&. 0x007fffff {- 2^23-1 -}
)) $ (-23)
I think it would be convenient to put such a function in random rather
than lots of packages implementing it themselves but I don't feel strongly
about it.
It seems there's general consensus that we should include generators for
floating point numbers but very little discussion on implementation
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6?email_source=notifications&email_token=AAABBQVHWLHH6JCTMYJ6JRLRDQ3UVA5CNFSM4KXLHWZ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IONR3XQ>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABBQSYS2RZFA6HIMIM5ITRDQ3UVANCNFSM4KXLHWZQ>
.
|
There are several algorithms available for generating random floating-point numbers. For example: I am aware of the Rademacher Floating-Point Library (by @christoph-conrads), which uses a sophisticated algorithm to generate random binary floating-point numbers in a range. However, the algorithm is far from trivial, and the author has yet to write up how the algorithm works. I am also aware of Allen Downey's investigation on generating random floating-point numbers, at least those bounded by 0 and 1. See also my section on Uniform Random Real Numbers. |
I'm digging into this a little. Again, thanks for the great pointers @peteroupc! The Rademacher Floating-Point Library comes with a test script. I'm going to try to hook it up to our Edit: see tweag/random-quality#18 |
I think from the discussion on #5 we are now saying this is out of scope and a generator for a floating point number should be obtained from another package. Does everyone agree? |
Random floating-point numbers should be generated using random integers, not the other way around. For example, I define the method However, precisely because generating random floating-point numbers in a range (any range, not just a range bounded by 0 and 1) is so tricky (besides resorting to dividing a random integer by a constant), declaring random floating-point generators as "out of scope" in this library should not foreclose any efforts in specifying a "complete" and correct algorithm for generating such numbers (where "complete" is used with the meaning in FloatingInterval). Once such an algorithm is specified, FloatingInterval and other applications can use it. |
Yep, that's understood. I think that's what @idontgetoutmuch meant too: the algorithm that takes a random number generator (as defined in the new
I think that's the idea: it would be good to have a "complete" floating point number generator in this sense. But we would also like to make progress on fixing other issues with |
Frankly I think this is ridiculous! So yes, you have generic API but to do anything useful with it you need another package. I think that sort of standard library for working with random numbers should be at least usable. I think it's fail to discuss whether Discussion #5 is very limited. It's only about primitives and not about API at large. How should we reconcile two variants: pure PRNG and stateful PRNG. How should we deal with PRNG initialization, handle seeds etc. I have proposal and I'll post it over the weekend |
lol - @Shimuuar I thought you did not agree with including a way of generating floating point random numbers (from a uniform distribution) - my misunderstanding. |
Great :) |
I guess I didn't make myself clear. Good library for PRNG is many layered cake and floating point don't belong to lowest level but absolutely must be included on the higher levels |
Fact. Eg in my Linked example
…On Fri, Feb 21, 2020 at 8:35 AM Aleksey Khudyakov ***@***.***> wrote:
I guess I didn't make myself clear. Good library for PRNG is many layered
cake and floating point don't belong to lowest level but absolutely must be
included on the higher levels
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6?email_source=notifications&email_token=AAABBQXYTKD65UZIRUZJUCTRD7KDHA5CNFSM4KXLHWZ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMSW3CY#issuecomment-589655435>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAABBQXDW6XSXJGHMI4KGI3RD7KDHANCNFSM4KXLHWZQ>
.
|
Let's stay friendly here.
Yes, I think at this point it's clear that we need a concrete proposal that can then be criticised in a constructive manner. I fully agree with the "many layered cake" picture - that's the idea I tried to get across in #5 (comment). What is not clear to me at this point is which of those layers should be provided by the new One piece of prior art here is Rust's So in that sense,
Could you explain what you mean by this?
That's great, thanks for taking the lead here. I look forward to reading the proposal. |
@cartazio wrote:
Which linked example? |
I believe random should provide both the low-level api for generating primitive types and on top of that should provide a higher level state-monad-like interface for how to use those primitives. This should be in conjunction with something like mwc-probability which provides a wide variety of different distributions one might need and can include various methods for generating floating point numbers etc. I strongly believe this should be part of a single package |
@Boarders I disagree with you about providing functionality for other distributions:
Here are a few arguments against including many distributions in
|
I agree with @lehins here and want to add that distribution generators require quite a bit of supporting infrastructure: vector, special functions. Those are really complicated beast which in fact doesn't care about details of PRNG implementation and only need way to generate uniform numbers. Also lack of generic API for random really hamstrung development of such libraries. Why |
Closing as we now have: #49 |
This question surfaced in discussion on PR #1 but it wasn't discussed in any depth. Here is quote and links from @cartazio:
@idontgetoutmuch
It seems there's general consensus that we should include generators for floating point numbers but very little discussion on implementation
The text was updated successfully, but these errors were encountered: