<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-01-18 9:35 GMT+01:00 Nadav Har'El <span dir="ltr"><<a href="mailto:nyh@scylladb.com" target="_blank">nyh@scylladb.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">On Wed, Jan 18, 2017 at 1:58 AM, <a href="mailto:alebarde@gmail.com" target="_blank">alebarde@gmail.com</a> <span dir="ltr"><<a href="mailto:alebarde@gmail.com" target="_blank">alebarde@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-m_-1026104553841207035gmail-">2017-01-17 22:13 GMT+01:00 Nadav Har'El <span dir="ltr"><<a href="mailto:nyh@scylladb.com" target="_blank">nyh@scylladb.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-m_-1026104553841207035gmail-m_5178951008414197177gmail-">On Tue, Jan 17, 2017 at 7:18 PM, <a href="mailto:alebarde@gmail.com" target="_blank">alebarde@gmail.com</a> <span dir="ltr"><<a href="mailto:alebarde@gmail.com" target="_blank">alebarde@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div>Hi Nadav,<br><br></div>I may be wrong, but I think that the result of the current implementation is actually the expected one.<br></div>Using you example: probabilities for item 1, 2 and 3 are: 0.2, 0.4 and 0.4<br><br></div><div>P([1,2]) = P([2] | 1st=[1]) P([1]) + P([1] | 1st=[2]) P([2])<br></div></div></blockquote><div><br></div></span><div>Yes, this formula does fit well with the actual algorithm in the code. But, my question is *why* we want this formula to be correct:<br><br></div></div></div></div></blockquote></span><div>Just a note: this formula is correct and it is one of statistics fundamental law: <a href="https://en.wikipedia.org/wiki/Law_of_total_probability" target="_blank">https://en.wikipedia.org/wiki/<wbr>Law_of_total_probability</a> + <a href="https://en.wikipedia.org/wiki/Bayes%27_theorem" target="_blank">https://en.wikipedia.org/wiki/<wbr>Bayes%27_theorem</a></div></div></div></div></blockquote><div><br></div></span><div>Hi,<br><br>Yes, of course the formula is correct, but it doesn't mean we're not applying it in the wrong context.<br></div><div><br>I'll be honest here: I came to numpy.random.choice after I actually
coded a similar algorithm (with the same results) myself, because
like you I thought this was the "obvious" and correct algorithm. Only then
I realized that its output doesn't actually produce the desired
probabilities specified by the user - even in the cases where that is possible. And I started wondering if existing libraries - like numpy - do this differently. And it turns out, numpy does it (basically) in the same way as my algorithm.<br> </div><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Thus, the result we get from random.choice IMHO definitely makes sense.</div></div></div></div></blockquote><div><br></div></span><div>Let's look at what the user asked this function, and what it returns:<br><br>User asks: please give me random pairs of the three items, where item 1 has probability 0.2, item 2 has 0.4, and 3 has 0.4.<br><br></div><div>Function returns: random pairs, where if you make many random returned results (as in the law of large numbers) and look at the items they contain, item 1 is 0.2333 of the items, item 2 is 0.38333, and item 3 is 0.38333.<br></div><div>These are not (quite) the probabilities the user asked for... <br></div><div><br></div><div>Can you explain a sense where the user's requested probabilities (0.2, 0.4, 0.4) are actually adhered in the results which random.choice returns?<br></div></div></div></div></blockquote><div><br></div><div>I think that the question the user is asking by specifying p is a slightly different one: <br></div><div> "please give me random pairs of the three items extracted from a population of 3 items where item 1 has probability of being extracted of 0.2, item 2 has 0.4, and 3 has 0.4. Also please remove extract items once extracted."<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"></div><div class="gmail_extra">Thanks,<br></div><div class="gmail_extra">Nadav Har'El.<br></div><div class="gmail_extra"><br></div></div>
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/<wbr>mailman/listinfo/numpy-<wbr>discussion</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><font size="1">--------------------------------------------------------------------------</font><font size="1"><br>
NOTICE:</font><font size="1"> Dlgs 196/2003 this e-mail and any attachments thereto may contain confidential information and are intended for the sole
use of the recipient(s) named above. If you are not the intended
recipient of this message you are hereby notified that any dissemination
or copying of this message is strictly prohibited. If you have received
this e-mail in error, please notify the sender either by telephone or
by e-mail and delete the material from any computer. Thank you.</font><font size="1"><br>
------------------------------</font><font size="1">------------------------------</font><font size="1">--------------</font></div>
</div></div>