How can I generate random permutations of [n] with k cycles, where k is much larger than log n? - MathOverflow most recent 30 from http://mathoverflow.net2013-05-19T17:16:19Zhttp://mathoverflow.net/feeds/question/3330http://www.creativecommons.org/licenses/by-nc/2.5/rdfhttp://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-largHow can I generate random permutations of [n] with k cycles, where k is much larger than log n?Michael Lugo2009-10-29T20:04:09Z2010-06-03T23:15:51Z
<p>I've been thinking a lot lately about random permutations. It's well-known that the mean and variance of the number of cycles of a permutation chosen uniformly at random from S<sub>n</sub> are both asymptotically log n, and the distribution is asymptotically normal.</p>
<p>I want to know what a typical permutation of [n] with k(n) cycles "looks like" (in terms of cycle structure), where k(n)/(log n) → ∞ as n → ∞. The special case I have in mind is permutations of [n] with n<sup>1/2</sup> cycles, since I've come across such permutations in another context, but I'm also curious about the more general problem. In order to do this I would like an algorithm that generates permutations of n with k cycles uniformly at random -- that is, it generates each one with probability 1/S(n,k) where S(n,k) is a Stirling number of the first kind -- so that I can experiment on them. (I'd be willing to settle for a Markov chain that converges to this distribution if it does so reasonably quickly.)</p>
<p>Unfortunately the only way I know to do this is to take a permutation of [n] uniformly at random (this is easy) and then throw it out if it doesn't have k cycles. If k is far from log(n) this is very inefficient, since those permutations are rare.</p>
<p>A few references I've come across that are related: <a href="http://www.combinatorics.org/Volume_13/JOC/v13i1r107p.pdf" rel="nofollow">This paper of Granville</a> looks at permutations with o(n<sup>1/2-ε</sup>) cycles or Ω(n<sup>1/2+ε</sup>) cycles and shows that their cycle lengths are "Poisson distributed", but right around n<sup>1/2</sup> is a transitional zone. And <a href="http://www.mathnet.ru/php/archive.phtml?wshow=paper&jrnid=dm&paperid=212&option_lang=eng" rel="nofollow">this paper of Kazimirov</a> studies "the asymptotic behavior of various statistics" under the distribution I've claimed, but I haven't read it yet because I can't read Russian and I'm waiting for the English translation. Finally, the algorithm I'm looking for might be in one of the fascicles of volume 4 of Knuth, but our library doesn't have them.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3358#3358Answer by omer angel for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?omer angel2009-10-30T00:23:37Z2009-10-30T00:23:37Z<p>One Markov chain that works: Pick uniformly two cycles <em>A,B</em>, and repartition their union uniformly into two new cycles. This is reversible, hence the uniform measure is stationary.</p>
<p>It would be interesting to know how fast this mixes.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3412#3412Answer by Mikael Vejdemo-Johansson for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Mikael Vejdemo-Johansson2009-10-30T06:25:50Z2009-10-30T06:25:50Z<p>Knowing next to nothing about randomness, this is how I'd go about picking a random permutation of [k] with exactly n cycles:</p>
<p>1) Pick n elements of k, removing each element from the pool you pick out of.
2) For the remaining elements, pick out an element at random, then pick an index i from [n] at random. Append the element to the cycle at i.</p>
<p>Alas, I don't really know how to analyze probabilities for this setup, nor to check what kind of distribution it gives.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3443#3443Answer by Pontus von Brömssen for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Pontus von Brömssen2009-10-30T14:04:33Z2009-10-30T14:04:33Z<p>I'm not sure this will help you, but you can compute the relative probabilities of the cycle types via <a href="http://en.wikipedia.org/wiki/Ewens%27s%5Fsampling%5Fformula" rel="nofollow">Ewens's sampling formula</a> (with θ=1).</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3517#3517Answer by Ori Gurel-Gurevich for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Ori Gurel-Gurevich2009-10-31T07:14:29Z2009-10-31T07:14:29Z<p>Another Markov chain which converges to the uniform distribution is a variation on the "random to random" shuffling:
pick a random element, take it out of the permutation and then stick it back in a random place, unless the random element you picked was a unicycle in which case you have to put it back as a unicycle to preserve the number of cycles.</p>
<p>This probably converges much more slowly than Omer's chain (at least for k << n), but it does have the advantage that, unless I'm mistaken, one can use path coupling to bound the mixing time by something like n^2 log n. If I had to guess I'd say the real mixing time is n log n. Luckily, I don't.</p>
<p>Perhaps path coupling could work for Omer's chain as well.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3518#3518Answer by jj-joerg-arndt for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?jj-joerg-arndt2009-10-31T07:22:46Z2009-10-31T07:22:46Z<p>Various algorithms for the unbiased generation of random permutations of certain types
(such as permutations into k cycles) are given in this thesis submitted just yesterday:
<a href="http://www.jjj.de/pub/" rel="nofollow">http://www.jjj.de/pub/</a>
Hope this helps, jj</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3527#3527Answer by Anon for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Anon2009-10-31T10:18:16Z2009-10-31T10:18:16Z<p>Look at the following paper:
Moni Naor, Omer Reingold: Constructing Pseudo-Random Permutations with a Prescribed Structure. J. Cryptology 15(2): 97-102 (2002)
You can find it on Moni's site.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/8248#8248Answer by Boaz Tsaban for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Boaz Tsaban2009-12-08T21:01:39Z2009-12-08T22:00:25Z<p>Naor and Reingold's paper, mentioned in <a href="http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/3527#3527" rel="nofollow">this answer</a>, only explains how to construct a random permutation with a <strong>fixed</strong> prescribed structure from a given random permuation P. </p>
<p>This is done by taking the simplest possible permutation with the structure you wish to get, and conjugating it by P.</p>
<p>This reduces the problem to choosing a k-cycles cycle structure with the correct distribution, which does not seem to be easier to me.</p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/21896#21896Answer by Herb Wilf for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?Herb Wilf2010-04-19T21:16:35Z2010-04-19T21:16:35Z<p>Youll find the answer on page 38 of my lecture notes East Side, West Side, which are a free download from my web site. It's a complete, short Maple program. The problem was originally solved in 1978 in Combinatorial Algorithms, by Albert Nijenhuis and myself.</p>
<p>Herb Wilf </p>
http://mathoverflow.net/questions/3330/how-can-i-generate-random-permutations-of-n-with-k-cycles-where-k-is-much-larg/26974#26974Answer by James Martin for How can I generate random permutations of [n] with k cycles, where k is much larger than log n?James Martin2010-06-03T21:34:44Z2010-06-03T23:15:51Z<p>One can sample from the uniform distribution on permutations on $n$ elements with $k$ cycles in expected time $O(n\sqrt{k})$. </p>
<p>For large $n$ and $k$ this may be more feasible than
the method Herb Wilf refers to in his answer, which,
if I understand right, requires the generation of the Stirling cycle numbers $S(m,r)$
for $m\leq n$ and $r\leq k$. </p>
<p>The idea is as follows: consider a Poisson-Dirichlet($\theta$) partition of $[n]$. The
blocks of such a partition have the distribution of the cycles of a random permutation
of $[n]$ from the distribution which gives weight proportional to $\theta^r$ to any permutation with $r$ cycles. In particular, conditioned on the number of cycles, the permutation is uniformly distributed. (Once one has a partition into blocks corresponding to the cycles, one can just fill in the elements of $[n]$ into the positions in the cycles uniformly at random). </p>
<p>Choose $\theta$ in such a way
that the mean number of cycles is around $k$.
One can sample a PD($\theta$) partition of $[n]$ in time $O(n)$ (see below).
Keep generating independent samples of the partition until you get one
with exactly $k$ blocks.
The variance of the number of cycles will be $O(k)$ (see below) and the
probability that the number of cycles is precisely $k$ will be on the order of $1/\sqrt{k}$, so
one will need to generate
$O(\sqrt{k})$ such samples before happening upon one with precisely $m$ cycles.</p>
<p>So this is really not so far from what you suggested in the question
(generate random permutations until you find one that fits) with the twist that
instead of generating from the uniform distribution (which corresponds to PD(1))
you choose a better value of $\theta$ and generate from PD($\theta$).</p>
<p>Here are two nice ways to sample a PD($\theta$) partition of $[n]$:</p>
<p>(1) "Chinese restaurant process" of Dubins and Pitman.
We add elements to the partition one by one. Element 1 starts in a block on its own. Thereafter, when we add element $r+1$,
suppose there are currently $m$ blocks whose sizes are $n_1, n_2, ... n_m$. Add element $r+1$ to block $i$ with probability
$n_i/(r+\theta)$, for $1\leq i\leq m$, and put element $r+1$ into a new block on its own with probability $\theta/(r+\theta)$. </p>
<p>(2) "Feller representation". Generate independent Bernoulli random variables $B_1, \dots, B_n$ with $P(B_i=1)=\theta/(i-1+\theta)$.
Write a string of length $n$ divided up into blocks, with the rule that we start a new block before position $i$ whenever $B_i=1$.
So for example if $n=10$ with $B_1=B_5=B_6=B_9=1$ and the other $B_i$ equal to 0, then the pattern is</p>
<p>(a b c d)(e)(f g h)(i j).</p>
<p>(Note that always $B_1=1$). Then assign the elements of $[n]$ to the positions in the blocks uniformly at random.</p>
<p>The expected number of blocks is $\sum_{i=1}^n \mathbb{E}B_i$, which is $\sum_{i=1}^n \theta/(i+\theta)$,
which is approximately $\theta(\log n-\log \theta)$. If this is equal to $k$ with $1 << k << n$, then
the number of blocks will be approximately normal with mean $k$ and variance $O(k)$. </p>
<p>For details of some of the things mentioned here
to do with Poisson-Dirichlet partitions, random permutations etc, see e.g. Pitman's lecture notes from
Saint-Flour: <a href="http://bibserver.berkeley.edu/csp/april05/bookcsp.pdf" rel="nofollow">http://bibserver.berkeley.edu/csp/april05/bookcsp.pdf</a></p>