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
mir.random.nonuniform: Add Ziggurat method for Normal & Exponential #261
Conversation
} | ||
}; | ||
|
||
return Ziggurat!(T, fallback, R, true)(pdf, invPdf, 128, rightEnd, T(9.91256303526217e-3)); |
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.
I actually would like to run the initialization in CTFE as it will never change, but exp
uses inline assembler which isn't supported in CTFE :/
Has anyone an idea?
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.
Well, start by filing an issue against phobos asking for a CTFE'able exp
.
BTW where on earth does this magic constant 9.91256...e-3
come from? I would suggest making it a named manifest constant.
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.
Well, start by filing an issue against phobos asking for a CTFE'able exp.
Ok thanks - done. I will test whether copying the non-inline version from Phobos works.
BTW where on earth does this magic constant 9.91256...e-3 come from? I would suggest making it a named manifest constant.
It also comes from [Marsaglia00] - there it's called v
.
It's the area of every block and thus depends on k
and the distribution.
-> I will declare it more explicitly.
Current coverage is 96.74% (diff: 97.77%)@@ master #261 diff @@
==========================================
Files 19 21 +2
Lines 3262 3874 +612
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 3149 3748 +599
- Misses 113 126 +13
Partials 0 0
|
(will post more summaries here soon, here's a brief overview) Design flaws of the Ziggurat algorithmtwo main critics:
An Improved Ziggurat Method to Generate Normal Random Samples
|
btw an interesting overview paper is Gaussian Random Number Generators by Thomas et. al. |
Authors: Sebastian Wilzbach | ||
*/ | ||
|
||
module mir.random.nonuniform; |
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.
Minor, but didn't we agree to create a mir.random.distribution
package to contain everything ... ?
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.
See: #262
Does Ziggurat method yield better results for normal distribution then other methods in Atmosphere or dstats? |
What's the best way to compare? |
NormalDist CDF looks good from what I can judge Exp doesn't |
If you don't know if Ziggurat yield better result, then we do not need Ziggurat |
There are no the best way. The best option is to read a couple of articles. We need to understand need we Ziggurat or not first, before spend time on it |
The existing academic literature would suggest that Ziggurat is a very effective method; the paper by Thomas et al. offers a variety of tests of statistical quality that could be used, IIRC. Question is, given the timelines, is it worth pushing on with Ziggurat, or would it be better to implement more basic implementations of the various distributions, and return to Ziggurat as a longer-term work? |
First question is Ziggurat better for basic distributions than basic implementations of them? If there no strong |
Yes sorry I should have been more precise. @9il what would be needed to convince you that Ziggurat is better than the algorithms in Atmosphere or dstats?
We have time at least time until October. I would prefer to go with the "better" algorithm and tune it. We already have the basics implementations in dstats against which we can benchmark and compare. |
Quote from my comment above:
|
Wallace-method is not specialised for Normal if I am not wrong |
Afaik Ziggurat is neither. In the literature it's just commonly only used for Normal and exponential distributions, however it's a general method that works for all monotone decreasing distributions (or if their symmetric half is monotone decreasing) |
I would say, "Yes, but." The "but" is because Ziggurat is more complicated to implement correctly (as we're learning). So, in terms of the current project, I would say there's a tradeoff between focusing on Ziggurat correct, versus getting a good variety of basic distributions in place with simpler (but more limited) algorithms. |
Yes, exactly. |
The emails I'm getting from GSoC suggest that we're supposed to be finished up by the end of August, with 23 August as your own deadline for finalizing code and 29 August as the deadline for Ilya and me to submit our final evaluation report? |
Yep, but that doesn't stop me to continue to work (I know that I wasted quite a lot of time) |
It's great that you want to keep working, but I was concerned about the expectations raised in the description of your GSoC project and what the people responsible might expect to see (which is why earlier I raised the possibility of doing some basic implementations of a variety of non-uniform distributions). @9il you're the primary mentor here, so what are your thoughts? |
We already have 2 general purpose Discrete RNG realizations and Tinflex will be ready soon. Tinflex is hard numeric project without obvious workforce requirements. R version contains a lot of numeric bugs, many of them are fixed in the this project. We can stamp / copy-past boost rng, and this is not problem. But copy-pasting is not related to the proper RNG numbers. First, we need proper shell over std.random and fixed If @wilzbach implemented a variety of non-uniform distributions but not Tinflex, then I would not be able to consider this GSoC project as finished. |
I agree with that; I'm asking whether we should implement a variety of non-uniform distributions instead of (short term) focusing on Ziggurat. Tinflex obviously takes primacy as it is the most significant part of the promised work. |
Yes, I prefer to add more a variety of non-uniform distributions instead of Ziggurat |
Please reopen for mir-random |
Adds the Ziggurat sampling algorithm for Normal & Exponential distribution.
-0.02
:/dub ./examples/nonuniform_plot.d
):Ping @joseph-wakeling-sociomantic @9il