Algorithm for sampling without replacement?

前端 未结 6 1634
情歌与酒
情歌与酒 2020-12-02 13:56

I am trying to test the likelihood that a particular clustering of data has occurred by chance. A robust way to do this is Monte Carlo simulation, in which the associations

6条回答
  •  臣服心动
    2020-12-02 14:31

    Another algorithm for sampling without replacement is described here.

    It is similar to the one described by John D. Cook in his answer and also from Knuth, but it has different hypothesis: The population size is unknown, but the sample can fit in memory. This one is called "Knuth's algorithm S".

    Quoting the rosettacode article:

    1. Select the first n items as the sample as they become available;
    2. For the i-th item where i > n, have a random chance of n/i of keeping it. If failing this chance, the sample remains the same. If not, have it randomly (1/n) replace one of the previously selected n items of the sample.
    3. Repeat #2 for any subsequent items.

提交回复
热议问题