From: Maxime Devos <maximedevos@telenet.be>
To: Keith Wright <kwright@keithdiane.us>
Cc: zelphirkaltstahl@posteo.de, guile-user@gnu.org
Subject: Re: Generating "independent" random numbers
Date: Wed, 11 Oct 2023 13:31:57 +0200 [thread overview]
Message-ID: <dd3509e2-6884-787a-d425-b58e4bc20d46@telenet.be> (raw)
In-Reply-To: <87mswqulir.fsf@free-comp-shop.com>
[-- Attachment #1.1.1: Type: text/plain, Size: 2825 bytes --]
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 #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2023-10-11 11:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 15:08 Generating "independent" random numbers Zelphir Kaltstahl
2023-10-03 16:04 ` tomas
2023-10-03 16:16 ` tomas
2023-10-03 22:17 ` Zelphir Kaltstahl
2023-10-03 22:16 ` Zelphir Kaltstahl
2023-10-03 18:25 ` Maxime Devos
2023-10-03 22:22 ` Zelphir Kaltstahl
2023-10-04 16:14 ` Keith Wright
2023-10-10 22:03 ` Maxime Devos
2023-10-10 23:04 ` Keith Wright
2023-10-11 11:31 ` Maxime Devos [this message]
2023-10-18 19:08 ` Mikael Djurfeldt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd3509e2-6884-787a-d425-b58e4bc20d46@telenet.be \
--to=maximedevos@telenet.be \
--cc=guile-user@gnu.org \
--cc=kwright@keithdiane.us \
--cc=zelphirkaltstahl@posteo.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).