Non-uniform randomness in Erlang? (as a feature)
Tue Jan 25 21:22:12 CET 2022
Many thanks for your answer. Re-using the vocabulary of : indeed the
alias method  that you chose looks very relevant when having a
distribution of discrete (rather than continuous) probabilities (and
this must be a lot simpler and more efficient than explicitly
transforming a probability density function  into a cumulative
distribution one , approximating its inverse and drawing uniformly
The implementation looks quite functional to me! The use of the array
module seems difficult to avoid. The precomputed term must remain quite
small. Then, as expected, two uniform draws are necessary per sample
generation; looks very reasonable. Maybe replacing calls to
crypto:rand_uniform/2 by calls to rand:uniform/1 could be relevant?
Weights could be I guess typed as number() rather than integer() (so
that they include probabilities already normalized in [0.0, 1.0]) with
no special change in the actual code.
Many thanks for sharing such a clear, referenced and compact
implementation - much appreciated!
Le 1/25/22 à 14:56, Sergey Prokhorov a écrit :
> I'm not sure I fully understand the terminology, but did I understand
> correctly that you are looking for some "random choice with weights"?
> I have implemented the "walker alias" algorithm some time ago
> But it is more or less a direct translation from imperative code, so
> it does not look really idiomatic.
> And it also only returns values from a predefined finite set, not via
> arbitrary density function.
> A bit in link with the recent message of Kenji regarding
> state-of-the-art random generators: if needing to draw samples from,
> this time, a specific, non-uniform distribution, are there Erlang
> libraries able to accept as input such a user-specified, arbitrary
> probability density function?
> (I searched for "Inverse transform sampling in Erlang" and alike,
> because of the statistical distribution of the same name, pointers
> difficult to find)
> Thanks in advance for any information,
> Best regards,
> Olivier Boudeville
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions