[Numpy-discussion] numpy.random.gamma returns 0 for small shape parameters
Uri Laserson
uri.laserson at gmail.com
Mon May 28 23:33:42 EDT 2012
I am trying to sample from a Dirichlet distribution, where some of the
shape parameters are very small. To do so, the algorithm samples each
component individually from a Gamma(k,1) distribution where k is the shape
parameter for that component of the Dirichlet. In principle, this should
always return a positive number (as the Dirichlet is defined). However, if
k is very small, it will return zero:
In [157]: np.random.gamma(1e-1)
Out[157]: 4.863866491339177e-06
In [158]: np.random.gamma(1e-2)
Out[158]: 2.424451829710714e-57
In [159]: np.random.gamma(1e-3)
Out[159]: 5.1909861689757784e-197
In [160]: np.random.gamma(1e-4)
Out[160]: 0.0
In [161]: np.random.gamma(1e-5)
Out[161]: 0.0
What is the best way to deal with this?
Thanks!
Uri
...................................................................................
Uri Laserson
Graduate Student, Biomedical Engineering
Harvard-MIT Division of Health Sciences and Technology
M +1 917 742 8019
laserson at mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120528/583c1cdb/attachment.html>
More information about the NumPy-Discussion
mailing list