Discussion:
[Numpy-discussion] PR 8053 np.random.multinomial tolerance param
Alex Beloi
2016-09-26 18:52:28 UTC
Permalink
Hello,



Pull Request: https://github.com/numpy/numpy/pull/8053



I would like to expose a tolerance parameter for the function
numpy.random.multinomial.



The function `multinomial(n, pvals, size=None)` correctly raises exception
when `sum(pvals) > 1 + 1e-12` as these values should sum to 1. However,
other libraries often cannot or do not guarantee such level of precision.



Specifically, I have encountered issues with tensorflow function
tf.nn.softmax, which is expected to output a tensor whose values sum to 1,
but often with precision of only 1e-8.



I propose to expose the `1e-12` tolerance to a non-negative float parameter
with default value `1e-12`.



Alex
Stephan Hoyer
2016-09-26 18:59:00 UTC
Permalink
I would actually be just as happy to relax the tolerance here to 1e-8
always. I doubt this would catch any fewer bugs than the current default.
In contrast, adding new parameters adds cognitive overload for everyone
encountering the function.

Also, for your use case note that tensorflow has it's own function for
generating random values from a multinomial distribution:
https://www.tensorflow.org/versions/r0.10/api_docs/python/constant_op.html#multinomial
Post by Alex Beloi
Hello,
Pull Request: https://github.com/numpy/numpy/pull/8053
I would like to expose a tolerance parameter for the function
numpy.random.multinomial.
The function `multinomial(n, pvals, size=None)` correctly raises exception
when `sum(pvals) > 1 + 1e-12` as these values should sum to 1. However,
other libraries often cannot or do not guarantee such level of precision.
Specifically, I have encountered issues with tensorflow function
tf.nn.softmax, which is expected to output a tensor whose values sum to 1,
but often with precision of only 1e-8.
I propose to expose the `1e-12` tolerance to a non-negative float
parameter with default value `1e-12`.
Alex
_______________________________________________
NumPy-Discussion mailing list
https://mail.scipy.org/mailman/listinfo/numpy-discussion
Alex Beloi
2016-09-27 21:01:21 UTC
Permalink
Thanks for pointing out the tensorflow multinomial implementation, this will cover my use case perfectly.



The documentation on raises is redundant as well, the relevant information is mentioned in the parameter description. I’ve closed the PR.



Cheers,

Alex







From: NumPy-Discussion [mailto:numpy-discussion-***@scipy.org] On Behalf Of Stephan Hoyer
Sent: Monday, September 26, 2016 11:59 AM
To: Discussion of Numerical Python
Subject: Re: [Numpy-discussion] PR 8053 np.random.multinomial tolerance param



I would actually be just as happy to relax the tolerance here to 1e-8 always. I doubt this would catch any fewer bugs than the current default. In contrast, adding new parameters adds cognitive overload for everyone encountering the function.



Also, for your use case note that tensorflow has it's own function for generating random values from a multinomial distribution:

https://www.tensorflow.org/versions/r0.10/api_docs/python/constant_op.html#multinomial



On Mon, Sep 26, 2016 at 11:52 AM, Alex Beloi <***@samsung.com> wrote:

Hello,



Pull Request: https://github.com/numpy/numpy/pull/8053



I would like to expose a tolerance parameter for the function numpy.random.multinomial.



The function `multinomial(n, pvals, size=None)` correctly raises exception when `sum(pvals) > 1 + 1e-12` as these values should sum to 1. However, other libraries often cannot or do not guarantee such level of precision.



Specifically, I have encountered issues with tensorflow function tf.nn.softmax, which is expected to output a tensor whose values sum to 1, but often with precision of only 1e-8.



I propose to expose the `1e-12` tolerance to a non-negative float parameter with default value `1e-12`.



Alex

Loading...