[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generating "independent" random numbers
From: |
Maxime Devos |
Subject: |
Re: Generating "independent" random numbers |
Date: |
Wed, 11 Oct 2023 00:03:19 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 |
Op 04-10-2023 om 18:14 schreef Keith Wright:
From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
my goal is normal distributed floats (leaving aside the finite
nature of the computer and floats).
Warning: I am out of my depth, I can't even spell statisticion, but...
The following is either provably correct up to round-off,
or totally stupid.
It's not stupid at all, but neither is it correct (the basic approach is
correct, and holds more generally for other probability distributions as
well, but some important details are off ...).
First define the cumulative distribution for the normal distribution:
$$f(x)= \frac{1}{\sqrt{\pi}} \int_{-\infty}^{x} e^{-x^2/2} dx $$
Instead of sqrt(pi) you need sqrt(2pi).
Also, this is the pdf, not the cdf. For the cdf, you need integrate this
expression from -infinity to x.
Now to get a normal random variable, let $u$ be a uniform random number
on [0,1), then $f^{-1}(u)$ is a standard normal random variable.
Computing the inverse of the cumulative normal distribution is left as
an exercise, because I don't know how, but it seems possible.
While the pdf is easy to invert (multiply by constant factor, take log,
multiply by constant factor), resulting in an expression only involving
constants, multiplication, logarithms (and, depending on simplification,
subtraction), the cdf isn't.
See https://en.wikipedia.org/wiki/Normal_distribution, in particular
‘Quantile function’. Unfortunately, erf^-1 is not straightforward to
approximate (though methods definitely exists -- it's the theory of the
approximation method that is difficult, not the implementation;
transcribing some implementation from Fortran to Scheme is tedious but
straightward).
Best regards,
Maxime Devos
OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature