Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSwitch Random to use the PCG RNG #643
Conversation
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jul 7, 2016
Contributor
Closing due to performance concerns surfaced by project-fuzzball. If a 32-bit version turns out to be acceptably fast and statistically robust, I'll submit another PR.
|
Closing due to performance concerns surfaced by project-fuzzball. If a 32-bit version turns out to be acceptably fast and statistically robust, I'll submit another PR. |
mgold
closed this
Jul 7, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Jul 7, 2016
Member
Also, it would be good to know if #636 has changed the randomness for the better in the bad cases you found earlier. It will be out in whatever is the next release, but I think that's a good reference point for any changes we want to make.
|
Also, it would be good to know if #636 has changed the randomness for the better in the bad cases you found earlier. It will be out in whatever is the next release, but I think that's a good reference point for any changes we want to make. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jul 8, 2016
Contributor
I will rerun the statistical tests with that change in place and let you know.
|
I will rerun the statistical tests with that change in place and let you know. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jul 8, 2016
Contributor
The test suite hasn't finished yet but the results are basically unchanged. It still fails the first test after two seconds of scrutiny, so it's not magically better. That said, I have yet to see how PCG in 32 bits will perform.
|
The test suite hasn't finished yet but the results are basically unchanged. It still fails the first test after two seconds of scrutiny, so it's not magically better. That said, I have yet to see how PCG in 32 bits will perform. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
shmookey
Jul 8, 2016
@mgold any chance you could elaborate (not necessarily here) on the performance figures you're seeing out of this? It's interesting and a little disappointing that an algorithm selling itself as among the very fastest would turn out to be unacceptably slow.
shmookey
commented
Jul 8, 2016
|
@mgold any chance you could elaborate (not necessarily here) on the performance figures you're seeing out of this? It's interesting and a little disappointing that an algorithm selling itself as among the very fastest would turn out to be unacceptably slow. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Jul 9, 2016
Contributor
PCG is (apparently) fast on 64-bit hardware. When you have to simulate that using immutable 32-bit integers, and where bitwise ops become several layers of lookups rather than opcodes, the implementation slows down considerably. See this code.
As for figures, in a real-world use, the current elm-test and core Random run in about 30ms. With the next version of elm-test that uses mgold/elm-random-pcg, it runs in about 3s. With a stubbed version of PCG (same API but logic is gutted), it runs in about 250ms. We are still investigating these performance regressions. I mentioned "how PCG in 32 bits will perform", and let me clarify that I mean both speed and statistical quality. We're looking for a compromise point with acceptable levels of each.
|
PCG is (apparently) fast on 64-bit hardware. When you have to simulate that using immutable 32-bit integers, and where bitwise ops become several layers of lookups rather than opcodes, the implementation slows down considerably. See this code. As for figures, in a real-world use, the current elm-test and core Random run in about 30ms. With the next version of elm-test that uses |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
For more performance notes, see here. |
mgold commentedJun 10, 2016
•
edited
Edited 1 time
-
mgold
edited Jun 11, 2016 (most recent)
As discussed in person, this commit changes the Random library to use the PCG generator. If you have 2 minutes to spare, you can read more about PCG here.
Changes:
Seednow contains only anInt64, a new private type.peelandnext.int,float, andinitialSeedhave all been pretty drastically changed. I also implementedbooldirectly withpeelandnext.Not changed:
Seedsay, "Whenever you want to use a generator, you need to pair it with a seed." This is no longer true (at least for user-managed seeds).initialSeedsay, "A good way to get an unexpected seed is to use the current time." From a randomness perspective, the current time is not as random as it could be; it can be predicted approximately. But more importantly, there's no way to get the current time without using effects of some kind, at which point you might as well use the effects manager.Opportunities for expansion:
constant, like we discussed.initialSeed2 : Int -> Int -> Seed. Currently, the least significant 32 bits are initialized to zero. Like using the current time, this works well enough for most people, but it's not as random as it could be. To implement, pass the new parameter (with>>> 0to be safe) as the second argument toInt64, which is0ininitialSeed.magicIncrementand keeping the increment in the seed itself. More info is in the comments. Working implementation inmgold/elm-random-pcg. I've found that the best interface is notSeed -> (Seed, Seed)butGenerator Seed(so if you want n independent seeds, useRandom.list n).Math.floor(Math.random()*0xFFFFFFFF), which you can wrap in a Task that you don't even need to expose publicly (though that might be nice).Task.map2over that task twice and use it withinitialSeed2. It's possible to do this and make the effect manager's seed really good without changing the API at all.