help-octave
[Top][All Lists]

## Re: betarnd function

 From: antonio palestrini Subject: Re: betarnd function Date: Thu, 22 Feb 2007 23:32:17 +0100

```Thank you David,
the difference in speed is amazing!
Regarding random numbers I need often to generate
Pareto random numbers and since I didn't find them in Octave
(except for very few exceptions octave is a wonderful software for
statistical distributions)
I use the standard "inversion method" of a distrib function. That is,

function p = pareto_rnd(k,a,n)
p = k*rand(n,1).^(-1/a);
endfunction

where "k" is the location parameter and "a" the shape parameter.
The asymptotic properties of such distrib. requires n large. Even
though the above function is fast since is vectorized,  do you know of
a faster octave function?

Antonio

```
```antonio palestrini wrote:
> Dear David,
> I usually use the "beta_rnd" function. Are "betarnd" and "beta_rnd"
> the same
> or there is any difference in efficiency, etc.?
>
> Thanks
> Antonio
betarnd is the matlab statistics toolbox compatible name. Octave had
beta_rnd before matlab had betarnd. beta_rnd is deprecated in favor of
betarnd. Note that I consider betarnd to be slow than it needs to be as
the randg function could be used to accelerate it. Consider

>> tic; b0 = betarnd(2,2,1,1e5); toc
Elapsed time is 10.041847 seconds.
>> tic; r1 = randg(2,1,1e5); b1 = r1 ./ (r1 + randg(2,1,1e5)); toc
Elapsed time is 0.073097 seconds.
>> hist(b0,[0.0125:0.025:0.9875]); hold on; hist(b1,[0.0125:0.025:0.9875])

As you see I can get about a factor of 140 speed up. I'll supply some
patches to make betarnd faster.

D.

--
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

```
```

--
Prof. Antonio Palestrini
DSGSS - University of Teramo, Italy