I have an integer N and I wish to generate one of its possible partitions uniformly at random. For example, N=5 has 7 partitions:
- (5) - K=1 part
- (4, 1) - K=2 parts
- (3, 2) - K=2 parts
- (3, 1, 1) - K=3 parts
- (2, 2, 1) - K=3 parts
- (2, 1, 1, 1) - K=4 parts
- (1, 1, 1, 1, 1) - K=5 parts
I want an algorithm that can output each one of these with probability 1/7.
Algorithms for generating all such partitions, or all partitions restricted to K parts, are easy to find.
However, what I'm looking for is not restricting K a priori. I cannot pick K uniformly at random, as the K are not uniformly distributed and the distribution is non-trivial. If I knew the precise distribution of part sizes beforehand I could sample K using it, then use one of the existing algorithms, but I could not find a way to do this. A numerical survey shows that the vast majority of partitions have small K.
I cannot generate the list of partitions beforehand, as for N=100 there are hundreds of millions of partitions already. But even for N=1000, which is on the range I need, each individual partition will be mostly a short list of small numbers.
Does such an algorithm exist? I could not find it and I've been searching it for days.
Aucun commentaire:
Enregistrer un commentaire