Content deleted Content added
m Fix empty citation, unnamed or unsupported parameter, or invalid parameter value using AutoEd; see Help:CS1 errors |
m convert special characters (via WP:JWB) |
||
Line 7:
# Generate a [[Uniform distribution (continuous)|uniform]] random variate {{math|0 ≤ ''x'' < 1}}.
# Let {{math|1=''i'' = ⌊''nx''⌋ + 1}} and {{math|1=''y'' = ''nx'' + 1 − ''i''}}. (This makes {{math|''i''}} uniformly distributed on {{math|{1, 2,
# If {{math|''y'' < ''U<sub>i</sub>''}}, return {{mvar|i}}. This is the biased coin flip.
# Otherwise, return {{mvar|K<sub>i</sub>}}.
An alternative formulation of the probability table, proposed by Marsaglia et. al.<ref name=marsaglia>{{Citation |first1=George |last1=Marsaglia |author-link1=George Marsaglia |first2=Wai Wan |last2=Tsang |first3=Jingbo |last3=Wang |title=Fast Generation of Discrete Random Variables |journal=Journal of Statistical Software |date=2004-07-12 |volume=11 |issue=3 |pages=1–11 |doi=10.18637/jss.v011.i03 |doi-access=free }}</ref> as the
==Table generation==
Line 17:
To generate the table, first initialize {{math|1=''U<sub>i</sub>'' = ''np<sub>i</sub>''}}. While doing this, divide the table entries into three categories:
* The
* The
* The
If {{math|1=''U<sub>i</sub>'' = 1}}, the corresponding value {{mvar|K<sub>i</sub>}} will never be consulted and is unimportant, but a value of {{math|1=''K<sub>i</sub>'' = ''i''}} is sensible.
Line 30:
# Assign entry {{mvar|i}} to the appropriate category based on the new value of {{mvar|U<sub>i</sub>}}.
Each iteration moves at least one entry to the
Vose<ref name=Vose/>{{Rp|974}} points out that floating-point rounding errors may cause the guarantee referred to in step 1 to be violated. If one category empties before the other, the remaining entries may have {{mvar|U<sub>i</sub>}} set to 1 with negligible error. The solution accounting for floating point is sometimes called the '''Walker-Vose method''' or the '''Vose alias method'''.
Line 50:
==Implementations==
* http://www.keithschwarz.com/darts-dice-coins/ Keith Schwarz: Detailed explanation, numerically stable version of
* http://apps.jcns.fz-juelich.de/ransampl Joachim Wuttke: Implementation as a small C library.
*https://gist.github.com/0b5786e9bfc73e75eb8180b5400cd1f8 Liam Huang's Implementation in C++
|