I've been using the random_element()
function provided by SAGE to generate random integer partitions for a given integer (N
) that are a particular length (S
). I'm trying to generate unbiased random samples from the set of all partitions for given values of N
and S
. SAGE's function quickly returns random partitions for N (i.e. Partitions(N).random_element()
).
However, it slows immensely when adding S
(i.e. Partitions(N,length=S).random_element()
). Likewise, filtering out random partitions of N
that are of length S
is incredibly slow.
However, and I hope this helps someone, I've found that in the case when the function returns a partition of N
not matching the length S
, that the conjugate partition is often of length S. That is:
S = 10
N = 100
part = list(Partitions(N).random_element())
if len(part) != S:
SAD = list(Partition(part).conjugate())
if len(SAD) != S:
continue
This increases the rate at which partitions of length S
are found and appears to produce unbiased samples (I've examined the results against entire sets of partitions for various values of N
and S
).
However, I'm using values of N (e.g. 10,000
) and S (e.g. 300
) that make even this approach impractically slow. The comment associated with SAGE's random_element()
function admits there is plenty of room for optimization. So, is there a way to more quickly generate unbiased (i.e. random uniform) samples of integer partitions matching given values of N
and S
, perhaps, by not generating partitions that do not match S
? Additionally, using conjugate partitions works well in many cases to produce unbiased samples, but I can't say that I precisely understand why.