How do I sample randomly based on some probability(wightage)?
smukh at cognobytes.com
Sun May 31 09:06:48 CEST 2009
On May 28, 3:52 pm, Antoon Pardon <apar... at forel.vub.ac.be> wrote:
> Op 2009-05-26, Arnaud Delobelle schreef <arno... at googlemail.com>:
> > Sumitava Mukherjee <sm... at cognobytes.com> writes:
> >> On May 26, 11:39 pm, Sumitava Mukherjee <sm... at cognobytes.com> wrote:
> >>> Hi all,
> >>> I need to randomly sample from a list where all choices have weights
> >>> attached to them. The probability of them being choosen is dependent
> >>> on the weights.
> >>> If say Sample list of choices are [A,B,C,D,E] and weights of the same
> >>> are [0.895,0.567,0.765,0.890,0.60] when I draw (say 2) samples then I
> >>> want the likeliness of them being chosen be in the order : D>A>C>E>B
> > You mean A > D > C > E > B
> >>> In short I mean if prob of a H is .9 and probability of T be 0.1 then
> >>> if I draw 10 samples, 9 should be H and 1 should be T.
> >>> I coudn't find a function in the module random that does so.
> >>> Please can someone guide me how the above could be implemented [either
> >>> through some function which exists and I don't know or pointers to
> >>> some code snippets which does so]?
> >>>>>> [Oh, I forgot to mention. I am looking for sampling without replacement.]
> > If you do sampling without replacement, you need to know the exact
> > number of each of A, B, C, D, E in the sample, not just their relative
> > frequency.
> As far as I understand, you are given the exact number of each. It is one.
> The numbers given are not relative frequencies of appearance but weights
> to be attributed for picking them.
> Antoon Pardon
Yes, the numbers are weights attributed for picking them.
More information about the Python-list