-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improve precision of rand sampling without conversion #79
Comments
@oscardssmith I think I misunderstood your comment first, this is about the "[1,2)-1" method for sampling uniformly from julia> bitstring.(filter(x -> x >= 1/2, rand(BFloat16, 50)))
20-element Vector{String}:
"0011111100010100"
"0011111101101100"
"0011111100111110"
"0011111101100110"
"0011111101001110"
"0011111101100100"
"0011111101110010"
"0011111100100010"
"0011111101110110"
"0011111101110110"
"0011111100011100"
"0011111100110110"
"0011111101000110"
"0011111100000110"
"0011111101100100"
"0011111100101100"
"0011111100000000"
"0011111101101100"
"0011111100011110"
"0011111100000010" (last bit is always zero) |
What's proposed here is better because it does sample from every float in julia> rand2(::Type{BFloat16}) = BFloat16(Float32(rand(UInt8)) * Float32(0x1.0p-8))
rand2 (generic function with 2 methods)
julia> bitstring.(filter(x -> 1/2 > x >= 1/4, [rand2(BFloat16) for i in 1:100]))
17-element Vector{String}:
"0011111010111000"
"0011111011010100"
"0011111011000000"
"0011111011000010"
"0011111010001110"
"0011111010011100"
"0011111010000110"
"0011111010000110"
"0011111010110100"
"0011111011100100"
"0011111010101000"
"0011111011111100"
"0011111011100000"
"0011111010011110"
"0011111011100000"
"0011111011100100"
"0011111010010110" And so statistically it's 1 bit of entropy better than the |
Originally posted by @oscardssmith in #73 (comment)
The text was updated successfully, but these errors were encountered: