[Numpy-discussion] Behavior of numpy.random.exponential

josef.pktd@gmai... josef.pktd@gmai...
Fri Mar 27 08:20:09 CDT 2009


On Fri, Mar 27, 2009 at 7:49 AM, Yves Frederix <yves.frederix@gmail.com> wrote:
> Hi,
>
> I noticed a problem with numpy.random.exponential. Apparently, the
> samples generated by numpy.random.exponential(scale=scale) follow the
> distribution f(x)=1/scale*exp(-x/scale) (and not
> f(x)=scale*exp(-x*scale) as stated by the docstring).
>
> The script below illustrates this.
>
> --
> import numpy as N
> import pylab as pl
>
> print N.__version__
>
> pl.figure()
>
> lamda = 2.
>
> noise_modulus = N.random.exponential(scale=lamda,\
>    size=(100000,))
> #noise_modulus = -N.log(N.random.uniform(size=(100000,)))/lamda # this works
>
> y_hist, x_hist = N.histogram(noise_modulus, bins=51,\
>        normed=True, new=True)
> x_pl = N.linspace(0, x_hist.max())
> pl.semilogy(x_hist[0:-1], y_hist, label='Empirical, lambda=%s' % lamda)
> pl.semilogy(x_pl, lamda * N.exp(-x_pl*lamda), ':', \
>        label='exact, lambda=%s' % lamda)
> pl.semilogy(x_pl, 1./lamda * N.exp(-x_pl*1./lamda), ':', \
>        label='exact, lambda=1/%s' % lamda)
>
> pl.legend(loc='best')
> pl.show()
>
> --
>
> Could this be a bug? I also checked with the latest svn version:
>
> In [1]: import numpy; numpy.__version__
> Out[1]: '1.4.0.dev6731'
>
> Best,
> YVES
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

I changed this a while ago in the documentation editor, but it hasn't
been merged yet to the source docstring

http://docs.scipy.org/numpy/docs/numpy.random.mtrand.RandomState.exponential/

There is also an open ticket for this http://projects.scipy.org/numpy/ticket/987

Can you review the new docstring, so we can mark it as reviewed and
close the ticket?

Josef


More information about the Numpy-discussion mailing list