<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 18, 2017 at 1:58 AM, <a href="mailto:alebarde@gmail.com">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-">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_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><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><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><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><br></div><div class="gmail_extra">Thanks,<br></div><div class="gmail_extra">Nadav Har'El.<br></div><div class="gmail_extra"><br></div></div>