guile-user
[Top][All Lists]
Advanced

[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 13:31:57 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0



Op 11-10-2023 om 01:04 schreef Keith Wright:
Maxime Devos <maximedevos@telenet.be> writes:

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).

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 ...).

Not surprising, I just made it up on the fly...

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).

Seems plausible.

Also, this is the pdf, not the cdf. For the cdf, you need integrate this
expression from -infinity to x.

I was using TeX notation.  That's exactly what $\int_{-\infty}^{x}$
means.

Ok, didn't notice the \int.

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.

I was thinking of numerical integration, but too busy to write the code.
>
I was feeling guilty about being so sloppy, and thinking of writing
it more carefully, but...

(the basic approach is correct, and holds more generally for other
probability distributions as well)

I just saw some pictures in my head and thought it must be a general
theorem, but it's so simple and general that it must be "well known".
Somebody sometime must have already written it better than I could;
but I don't know who.  It is Theorem (X?) on page (Y?) of book (Z?).

You can probably find it in most course texts on probability and random number generation. I could provide you a reference, but I don't think my source is publicly available.

-- Keith
PS: While we are cleaning up details, substitute "modulo" for "/" in:

From: Maxime Devos <maximedevos@telenet.be>

So, to generate an (approximately) uniform random number on [0,1), you
can simply do

(define (random-real)
     (exact->inexact (/ (random N) N)))

for a suitably l

I'm pretty sure '/' is correct here. (random N) produces integers in [0,N), dividing by N yields something in [0,1).

Best regards,
Maxime Devos.

Attachment: OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]