How do I generate a uniform random integer partition?

前端 未结 7 595
天命终不由人
天命终不由人 2020-12-14 08:31

A Google search reveals plenty about generating all possible partitions of an integer n into m parts, but I haven\'t found anything about sampling a uniformly distributed ra

7条回答
  •  生来不讨喜
    2020-12-14 09:24

    Another algorithm from Combinatorial Algorithms page 52, "Random Generation of n into k parts"

    1. Choose a1, a2, .. , ak-1 a random k-1 subset of {1,2,..,n+k-1} (see below 1., 2.)
    2. Set r1 = a1-1; rj = aj - aj-1-1 (j=2..k-1); rk = n+k-1- ak-1
    3. The rj (j=1..k) constitute the random partition of n into k parts

    This algorithm for random compositions is based on the "balls-in-cells" model.

    Briefly we choose the posiitons of the cell boundaries at random, then by differencing we find out how many balls are in each cell.

    For efficiently generating a random subset of a set, see a 1. related answer here and 2. here

    update

    Another approach using a single random number in [0,1] to uniformly generate a random partition (also called composition) is given in IVAN STOJMENOVIC, "ON RANDOM AND ADAPTIVE PARALLEL GENERATION OF COMBINATORIAL OBJECTS" (section 5, section 10)

提交回复
热议问题