Hi,
Is there a simple way to generate normally distributed random data in
CommonLisp? I'm looking for a package, that can handle this, and maybe
also other statistical stuff
best regards
Chris
On Jul 29, 3:00 am, ·················@googlemail.com"
<················@googlemail.com> wrote:
> Hi,
>
> Is there a simple way to generate normally distributed random data in
> CommonLisp? I'm looking for a package, that can handle this, and maybe
> also other statistical stuff
There's also CL-GSL, a CL foreign-function interface to the GNU
Statistics Library:
http://common-lisp.net/project/cl-gsl/
-- Scott
From: Raymond Toy (RT/EUS)
Subject: Re: Generating normally distributed randoms in CL
Date:
Message-ID: <sxdiquoai3g.fsf@rtp.ericsson.se>
>>>>> "krzysztof" == krzysztof <················@googlemail.com> writes:
krzysztof> Hi,
krzysztof> Is there a simple way to generate normally distributed random data in
krzysztof> CommonLisp? I'm looking for a package, that can handle this, and maybe
krzysztof> also other statistical stuff
You can find some in clocc (clocc.sourceforge.net). See
clocc/src/cllib/rng.lisp. (There are 6 different Gaussian generators there.)
Ray
From: Raymond Toy (RT/EUS)
Subject: Re: Generating normally distributed randoms in CL
Date:
Message-ID: <sxdej5cai0t.fsf@rtp.ericsson.se>
>>>>> "krzysztof" == krzysztof <················@googlemail.com> writes:
krzysztof> Hi,
krzysztof> Is there a simple way to generate normally distributed random data in
krzysztof> CommonLisp? I'm looking for a package, that can handle this, and maybe
krzysztof> also other statistical stuff
Sapaclisp ( http://common-lisp.net/project/sapaclisp/) has a bunch of
statistical stuff too, in addition to some rngs.
Ray
On Tue, 29 Jul 2008 03:00:22 -0700, ················@googlemail.com wrote:
> Hi,
>
> Is there a simple way to generate normally distributed random data in
> CommonLisp? I'm looking for a package, that can handle this, and maybe
> also other statistical stuff
Hi Chris,
Check out the package cl-variates.
Tamas
·················@googlemail.com" <················@googlemail.com> writes:
> Is there a simple way to generate normally distributed random data in
> CommonLisp?
Yes. Learning some probabilities.
> I'm looking for a package, that can handle this, and maybe
> also other statistical stuff
Google gives:
(DEFUN NORMAL-RANDOM ()
(* (SQRT (* -2.0L0 (LOG (- 1.0L0 (RANDOM 1.0L0)))))
(COS (* 2.0L0 PI (RANDOM 1.0L0)))))
do we really need yet another package for this simple function?
--
__Pascal Bourguignon__
>
> Yes. Learning some probabilities.
>
No. I'm just want to rewrite some simulation from Python, wchich has
that distribution included in built-in libraries.
>
> (DEFUN NORMAL-RANDOM ()
> (* (SQRT (* -2.0L0 (LOG (- 1.0L0 (RANDOM 1.0L0)))))
> (COS (* 2.0L0 PI (RANDOM 1.0L0)))))
>
> do we really need yet another package for this simple function?
>
> --
> __Pascal Bourguignon__
Thnx, I don't need any special package actually. BTW, is it an
implementation of Box-Muller algorithm?
regards
Chris
·················@googlemail.com" <················@googlemail.com> writes:
>>
>> Yes. �Learning some probabilities.
>>
> No. I'm just want to rewrite some simulation from Python, wchich has
> that distribution included in built-in libraries.
>
>
>> (DEFUN NORMAL-RANDOM ()
>> � (* (SQRT (* -2.0L0 (LOG (- 1.0L0 (RANDOM 1.0L0)))))
>> � � �(COS (* 2.0L0 PI (RANDOM 1.0L0)))))
>>
>> do we really need yet another package for this simple function?
>
> Thnx, I don't need any special package actually. BTW, is it an
> implementation of Box-Muller algorithm?
Yes, only in one dimension (or the projection of the real axis, if you will).
Also you may want this one: http://en.wikipedia.org/wiki/Ziggurat_algorithm
--
__Pascal Bourguignon__
On Tue, 29 Jul 2008 13:59:40 +0200, Pascal J. Bourguignon wrote:
> ·················@googlemail.com" <················@googlemail.com>
> writes:
>> Is there a simple way to generate normally distributed random data in
>> CommonLisp?
>
> Yes. Learning some probabilities.
I think this is a bad attitude in general. One can't know everything,
and one can't implement everything from scratch. Or even if you can,
sometimes your time is not worth it.
>> I'm looking for a package, that can handle this, and maybe also other
>> statistical stuff
>
> Google gives:
>
> (DEFUN NORMAL-RANDOM ()
> (* (SQRT (* -2.0L0 (LOG (- 1.0L0 (RANDOM 1.0L0)))))
> (COS (* 2.0L0 PI (RANDOM 1.0L0)))))
>
> do we really need yet another package for this simple function?
In some cases you can find simple algorithms that you can easily
implement, but having more advanced algorithms that are already written,
debugged and tested (like the Ziggurat algorithm below) is always nice.
For example, to solve differential equations, you can program an RK4
solver really quickly. But you may not want to program a sophisticated
adaptive-stepsize algorithm that handles stiffness when one is already
available.
Tamas
* Tamas K Papp <··············@mid.individual.net> :
Wrote on 30 Jul 2008 09:00:20 GMT:
| On Tue, 29 Jul 2008 13:59:40 +0200, Pascal J. Bourguignon wrote:
|> ·················@googlemail.com" <················@googlemail.com>
|> writes:
|>> Is there a simple way to generate normally distributed random data in
|>> CommonLisp?
[...]
|>> I'm looking for a package, that can handle this, and maybe also other
|>> statistical stuff
|>
|> (DEFUN NORMAL-RANDOM ()
|> (* (SQRT (* -2.0L0 (LOG (- 1.0L0 (RANDOM 1.0L0)))))
|> (COS (* 2.0L0 PI (RANDOM 1.0L0)))))
|>
|> do we really need yet another package for this simple function?
|
| In some cases you can find simple algorithms that you can easily
| implement, but having more advanced algorithms that are already written,
| debugged and tested (like the Ziggurat algorithm below) is always nice.
| For example, to solve differential equations, you can program an RK4
| solver really quickly. But you may not want to program a sophisticated
| adaptive-stepsize algorithm that handles stiffness when one is already
| available.
I suggest that there is another reason to use a well known
implementation.
For serious simulations you want to publish repeatable results,
_independent_ of the Common Lisp implementation you use---In that case
your simulation program cannot depend on a package which calls CL:RANDOM
[as different implementations will produce different sequences of
numbers]. It is preferable to use FFI to a "Standard" C implementation,
like the "RANLIB.C" package from NETLIB,
--
Madhu
On Jul 30, 12:01 pm, Madhu <·······@meer.net> wrote:
> * Tamas K Papp <··············@mid.individual.net> :
> Wrote on 30 Jul 2008 09:00:20 GMT:
> For serious simulations you want to publish repeatable results,
> _independent_ of the Common Lisp implementation you use---In that case
> your simulation program cannot depend on a package which calls CL:RANDOM
> [as different implementations will produce different sequences of
> numbers]. It is preferable to use FFI to a "Standard" C implementation,
> like the "RANLIB.C" package from NETLIB,
>
> --
> Madhu
In SBCL the random function uses the well known algorithm of Mersenne
Twister.
http://sbcl-internals.cliki.net/RANDOM-MT19937
* Leonardo Varuzza
Wrote on Wed, 30 Jul 2008 13:18:57 -0700 (PDT):
| In SBCL the random function uses the well known algorithm of Mersenne
| Twister.
So does CMUCL, but neither fact is relevant to the point I was making
here. I was talking of using a well known _implementation_, (not just
algorithm) in your simulation program, which would not depend on the
implementation's RANDOM
P� Wed, 30 Jul 2008 23:28:22 +0200, skrev Madhu <·······@meer.net>:
> * Leonardo Varuzza
> Wrote on Wed, 30 Jul 2008 13:18:57 -0700 (PDT):
>
> | In SBCL the random function uses the well known algorithm of Mersenne
> | Twister.
>
> So does CMUCL, but neither fact is relevant to the point I was making
> here. I was talking of using a well known _implementation_, (not just
> algorithm) in your simulation program, which would not depend on the
> implementation's RANDOM
>
That's just silly. Any random distribution function depends on the
randomness.
LW has a Merseyenne twister as well..
--------------
John Thingstad
"John Thingstad" <·······@online.no> writes:
> På Wed, 30 Jul 2008 23:28:22 +0200, skrev Madhu <·······@meer.net>:
>
>> * Leonardo Varuzza
>> Wrote on Wed, 30 Jul 2008 13:18:57 -0700 (PDT):
>>
>> | In SBCL the random function uses the well known algorithm of Mersenne
>> | Twister.
>>
>> So does CMUCL, but neither fact is relevant to the point I was making
>> here. I was talking of using a well known _implementation_, (not just
>> algorithm) in your simulation program, which would not depend on the
>> implementation's RANDOM
>>
>
> That's just silly. Any random distribution function depends on the
> randomness.
> LW has a Merseyenne twister as well..
I believe he's saying that it is often valuable (for simulation
verification purposes, artistic purposes, and so on) to be able to, at
will, generate the same series of numbers twice, and that identical
behavior is not guaranteed across implementations. Makes sense to me.
* "John Thingstad" <·················@pandora.alfanett.no> :
Wrote on Wed, 30 Jul 2008 23:53:13 +0200:
| På Wed, 30 Jul 2008 23:28:22 +0200, skrev Madhu <·······@meer.net>:
|
|> * Leonardo Varuzza
|> Wrote on Wed, 30 Jul 2008 13:18:57 -0700 (PDT):
|>
|> | In SBCL the random function uses the well known algorithm of Mersenne
|> | Twister.
|>
|> So does CMUCL, but neither fact is relevant to the point I was making
|> here. I was talking of using a well known _implementation_, (not just
|> algorithm) in your simulation program, which would not depend on the
|> implementation's RANDOM
|>
|
| That's just silly.
Why? Have you even attempted to understand the point I was trying to
make? It is really quite trivial. I dont see why it is so hard to
understand.
| Any random distribution function depends on the randomness.
| LW has a Merseyenne twister as well..
Completely irrelevant to my point again.
From: Raymond Toy (RT/EUS)
Subject: Re: Generating normally distributed randoms in CL
Date:
Message-ID: <sxd1w1b9l7y.fsf@rtp.ericsson.se>
>>>>> "Madhu" == Madhu <·······@meer.net> writes:
Madhu> I suggest that there is another reason to use a well known
Madhu> implementation.
Madhu> For serious simulations you want to publish repeatable results,
Madhu> _independent_ of the Common Lisp implementation you use---In that case
Madhu> your simulation program cannot depend on a package which calls CL:RANDOM
Madhu> [as different implementations will produce different sequences of
Madhu> numbers]. It is preferable to use FFI to a "Standard" C implementation,
Madhu> like the "RANLIB.C" package from NETLIB,
I would suggest that if your simulation results depended on the
sequence of random numbers, then your simulation is broken. Well,
assuming that the simulation wasn't about the rng, and assuming the
random number generator itself is not broken. :-)
Ray
* (Raymond Toy (RT/EUS)) <···············@rtp.ericsson.se> :
Wrote on Wed, 30 Jul 2008 16:21:37 -0400:
| Madhu> I suggest that there is another reason to use a well known
| Madhu> implementation.
|
| Madhu> For serious simulations you want to publish repeatable results,
| Madhu> _independent_ of the Common Lisp implementation you use---In
| Madhu> that case your simulation program cannot depend on a package
| Madhu> which calls CL:RANDOM [as different implementations will
| Madhu> produce different sequences of numbers]. It is preferable to
| Madhu> use FFI to a "Standard" C implementation, like the "RANLIB.C"
| Madhu> package from NETLIB,
|
| I would suggest that if your simulation results depended on the
| sequence of random numbers, then your simulation is broken.
No that is not what I'm suggesting.
The point I'm making is about getting the exact same simulation result
(after seeding the rng identically) on different runs of the
application. [This is often required to verify your simulation is NOT
broken in some ways]
If you switch lisp implementation you get a different number from your
program because you are switching the rng. The suggestion to use a well
known RNG was to get identical results regardless of the lisp
implementation.
Am I missing something?
| Well, assuming that the simulation wasn't about the rng, and assuming
| the random number generator itself is not broken. :-)
--
Madhu
From: Raymond Toy (RT/EUS)
Subject: Re: Generating normally distributed randoms in CL
Date:
Message-ID: <sxdwsj2899a.fsf@rtp.ericsson.se>
>>>>> "Madhu" == Madhu <·······@meer.net> writes:
Madhu> * (Raymond Toy (RT/EUS)) <···············@rtp.ericsson.se> :
Madhu> Wrote on Wed, 30 Jul 2008 16:21:37 -0400:
Madhu> | Madhu> I suggest that there is another reason to use a well known
Madhu> | Madhu> implementation.
Madhu> |
Madhu> | Madhu> For serious simulations you want to publish repeatable results,
Madhu> | Madhu> _independent_ of the Common Lisp implementation you use---In
Madhu> | Madhu> that case your simulation program cannot depend on a package
Madhu> | Madhu> which calls CL:RANDOM [as different implementations will
Madhu> | Madhu> produce different sequences of numbers]. It is preferable to
Madhu> | Madhu> use FFI to a "Standard" C implementation, like the "RANLIB.C"
Madhu> | Madhu> package from NETLIB,
Madhu> |
Madhu> | I would suggest that if your simulation results depended on the
Madhu> | sequence of random numbers, then your simulation is broken.
Madhu> No that is not what I'm suggesting.
Madhu> The point I'm making is about getting the exact same simulation result
Madhu> (after seeding the rng identically) on different runs of the
Madhu> application. [This is often required to verify your simulation is NOT
Madhu> broken in some ways]
Agreed. Especially if you're debugging something and the bug keeps
moving because the seed is different on each run. But it's also good
to use a different seed and/or rng once in a while to make sure some
weird scenario is handled.
Madhu> If you switch lisp implementation you get a different number from your
Madhu> program because you are switching the rng. The suggestion to use a well
Madhu> known RNG was to get identical results regardless of the lisp
Madhu> implementation.
This is also one of the reasons I've never bothered to change CMUCL's
rng. There are new ones out there that are at least as good or better
in some way. But changing it breaks so many things because the
results won't be the same as before.
Madhu> Am I missing something?
Nothing really. I guess I should have put a smilely there. I think
it's good to use a different implementation once in a while to
discover any wierd issues.
I often times use gcc and Sun C to compile my code to see what bad
assumptions I may have made. Way back when we had this simulation
that worked beautifully. But when we recompiled the code for a
different machine, it was totally broken. Why? Because the compilers
on the different machines did different things for "uninitialized"
memory. One zeroed it out, the other left random bit there. The
program should have initialized memory itself.
Ray
On Jul 29, 7:00 am, ·················@googlemail.com"
<················@googlemail.com> wrote:
> Hi,
>
> Is there a simple way to generate normally distributed random data in
> CommonLisp? I'm looking for a package, that can handle this, and maybe
> also other statistical stuff
>
> best regards
> Chris
I implemented the Ziggurat algorithm for normal variables in Common
lisp (the same used in GSL).
This code and other random numbers generators are availiable in my
package:
http://code.google.com/p/cl-randist/
Can also be get by asdf-install (asdf-install:install :cl-randist)
Or by git, with this command:
git clone http://lambdatau.com/git/cl-randist
Generanting normal distributed values with mean 0 and variance 1 is
simples as:
(randist:random-normal 0d0 1d0)
On 29 jul, 22:50, Leonardo Varuzza <·······@gmail.com> wrote:
> I implemented the Ziggurat algorithm for normal variables in Common
> lisp (the same used in GSL).
>
> This code and other random numbers generators are availiable in my
> package:
way to go, dude! ;)
> Is there a simple way to generate normally distributed random data in
> CommonLisp? I'm looking for a package, that can handle this, and maybe
> also other statistical stuff
Depending on you needs, the following might be good enough (passes
general normality tests for a few hundreds of numbers):
(- (loop for i from 1 to 12 sum (random 1d0)) 6)
From there you can go as far as you want to obtain the desired
accuracy (including tail corrections if needed). There is a recent
review of algorithms here:
http://www.cse.cuhk.edu.hk/~phwl/mt/public/archives/papers/grng_acmcs07.pdf
Personally I find methods based on the inverse normal cumulative
function simpler to understand and safer to use. Transformation and
rejection methods are clever, but they are sensible to problems with
the pseudo-random sequence (and using them with low-discrepancy
sequences is difficult, when possible at all).
Carlos