February 26, 2016 Re: Normal distribution | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 26 February 2016 at 20:15:10 UTC, Andrei Alexandrescu wrote:
> Would it work to define Gaussian generators as regular generators (same as the existing ones), which keep the uniform engine as a member?
Assuming that the uniform engine was uniquely and only used by that Gaussian generator, yes, that would be OK (although I think we can do better). If you try and take that approach using the same uniform generator as you're using in other parts of the code, it'll likely be problematic, unless the Gaussian stores a reference to that RNG rather than a by-value copy.
Another approach, maybe more flexible given the current state of things, would be to define a functor whose opCall takes a uniform RNG as a parameter by ref, and which returns floating-point values distributed according to the Gaussian distribution.
I still think, though, that we need to solve the fundamental architectural problems of how to implement random algorithms in range form, before we can really get a nice solution.
I'm going to try and prepare some notes on that soon -- bug me if I don't come up with the goods.
| |||
February 28, 2016 Re: Normal distribution | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Friday, 26 February 2016 at 20:15:10 UTC, Andrei Alexandrescu wrote: > On 2/26/16 2:32 PM, Joseph Rushton Wakeling wrote: >> Yup. The basic problem of getting this stuff into phobos are the >> architectural problems discussed in that talk. Unlike uniform >> distribution (which is straightforward to implement as a function, no >> questions asked), the normal distribution is best implemented as a range >> which keeps some state. So the reference-type/non-reference-type issues >> start becoming a factor. > > Would it work to define Gaussian generators as regular generators (same as the existing ones), which keep the uniform engine as a member? -- Andrei This C implementation of the Marsaglia/Tsang Ziggurat method keeps no state except for that of the uniform rng and 3 small static lookup tables that can be initialized in the module's shared constructor: http://people.sc.fsu.edu/~jburkardt/cpp_src/ziggurat_inline/ziggurat_inline.cpp I wrote a D implementation of that with the uniform rngs factored out, leaving it at ~50 loc - not up to Phobos' standards for sure - but I suppose but it could be a starting point. If someone is interested in that let me know. | |||
February 28, 2016 Re: Normal distribution | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Saturday, 20 February 2016 at 14:01:22 UTC, Andrei Alexandrescu wrote: > Do we have a good quality converter of uniform numbers to Gaussian-distributed numbers around? -- Andrei Forth Engineering Practice™ is to add a few uniform distributions together... http://www.colorforth.com/e-x2.htm Accurate to 2 decimal places! | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply