{"id":4836,"date":"2012-05-03T16:31:53","date_gmt":"2012-05-03T14:31:53","guid":{"rendered":"http:\/\/djalil.chafai.net\/blog\/?p=4836"},"modified":"2014-06-15T22:29:13","modified_gmt":"2014-06-15T20:29:13","slug":"generating-uniform-random-partitions","status":"publish","type":"post","link":"https:\/\/djalil.chafai.net\/blog\/2012\/05\/03\/generating-uniform-random-partitions\/","title":{"rendered":"Generating uniform random partitions"},"content":{"rendered":"<p style=\"text-align: center;\"><a href=\"http:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2012\/05\/set_partitions_5.png\" rel=\"attachment wp-att-4841\"><img loading=\"lazy\" class=\"aligncenter wp-image-4841 size-medium\" title=\"All partitions of a set of five elements (source: Wikipedia)\" src=\"http:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2012\/05\/set_partitions_5-300x124.png\" alt=\"All partitions of a set of five elements (source: Wikipedia)\" width=\"300\" height=\"124\" srcset=\"https:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2012\/05\/set_partitions_5-300x124.png 300w, https:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2012\/05\/set_partitions_5.png 722w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">This post is devoted to an algorithm due to Aart Johannes <b>Stam<\/b> for the simulation of the uniform law on the set \\( {\\Pi_n} \\) of partitions of \\( {\\{1,\\ldots,n\\}} \\). This law gives the same probability \\( {1\/B_n} \\) to every element of \\( {\\Pi_n} \\), where \\( {B_n=\\mathrm{Card}(\\Pi_n)} \\). In combinatorics, \\( {{(B_n)}_{n\\geq1}} \\) are the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bell_number\">Bell numbers<\/a>. We have \\( {B_1=1} \\), \\( {B_2=2} \\), and more generally, using the convention \\( {B_0=1} \\),<\/p>\n<p style=\"text-align: center;\">\\[ B_{n+1}=\\sum_{k=0}^n\\binom{n}{k}B_k \\]<\/p>\n<p style=\"text-align: justify;\">(here \\( {k} \\) stands for the number of elements outside the bloc containing \\( {n+1} \\)). Now, the formal series \\( {G(X)=\\sum_{n=0}^\\infty\\frac{B_n}{n!}X^n} \\) satisfies to \\( {G'(X)=\\exp(X)G(X)} \\), and thus<\/p>\n<p style=\"text-align: center;\">\\[ G(X)=\\exp(\\exp(X)-1). \\]<\/p>\n<p style=\"text-align: justify;\">We recognize the Laplace transform of the Poisson law of unit mean. In particular, the Bell numbers are the moments of this law, which gives the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Dobinski's_formula\">Dobinski formula<\/a>:<\/p>\n<p style=\"text-align: center;\">\\[ B_n=\\frac{1}{e}\\sum_{k=0}^\\infty\\frac{k^n}{k!}. \\]<\/p>\n<p style=\"text-align: justify;\">To simulate the uniform law on \\( {\\Pi_n} \\), the idea is to associate a random color to each element of \\( {\\{1,\\ldots,n\\}} \\) and to decide that elements of identical color are in the same bloc. More precisely, we first generate a random integer \\( {K} \\) taking the value \\( {k} \\) with probability \\( {k^n\/(k!eB_n)} \\) (this is a well defined law thanks to the Dobinski formula above). Next, conditional on \\( {K} \\), we generate i.i.d. random variables \\( {C_1,\\ldots,C_n} \\) according to the uniform law on \\( {\\{1,\\ldots,K\\}} \\). Finally, we define the random element \\( {P} \\) of \\( {\\Pi_n} \\) obtained by deciding that \\( {i} \\) and \\( {j} \\) are in the same bloc iff \\( {C_i=C_j} \\). It turns out that \\( {P} \\) follows the uniform law on \\( {\\Pi_n} \\) since for every \\( {p\\in\\Pi_n} \\) with say \\( {b} \\) blocs:<\/p>\n<p style=\"text-align: center;\">\\[ \\begin{array}{rcl} \\mathbb{P}(P=p) &amp;=&amp;\\sum_{k=b}^\\infty\\mathbb{P}(P=p|K=k)\\mathbb{P}(K=k)\\\\ &amp;=&amp;\\sum_{k=b}^\\infty\\frac{k(k-1)\\cdots(k-b+1)}{k^n}\\frac{k^n}{k!eB_n}\\\\ &amp;=&amp;\\frac{1}{B_n}. \\end{array} \\]<\/p>\n<p style=\"text-align: justify;\"><b>Exercice.<\/b> Evaluate the complexity of this algorithm!<\/p>\n<p style=\"text-align: justify;\"><b>References.<\/b><\/p>\n<ul>\n<li><a href=\"http:\/\/www.ams.org\/mathscinet-getitem?mr=712107\">Stam, Generation of a random partition of a finite set by an urn model. J. Combin. Theory Ser. A 35 (1983), no. 2, 231\u2013240<\/a>;<\/li>\n<li><a href=\"http:\/\/www.ams.org\/mathscinet-getitem?mr=2251472\">Knuth, The art of computer programming. Vol. 4, Fasc. 3. Generating all combinations and partitions. Addison-Wesley, 2005<\/a>.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><b>Note.<\/b> I've learnt this algorithm while writing an expository text with Yan Doumerc and Florent Malrieu on the chinese restaurant process. It is worth noting that the uniform law on \\( {\\Pi_n} \\) does not belong to the Ewens one parameter family of laws on partitions. This is in contrast with the <a href=\"\/blog\/2011\/06\/30\/random-uniform-permutations\/\">uniform law on permutations<\/a>, which coincides with the Ewens law of unit parameter.<\/p>\n<p style=\"text-align: justify;\"><b>Note.<\/b> One should not confuse finite set partitions with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Partition_(number_theory)\">integer partitions<\/a>, which are rather related to Young or Ferrers diagrams.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is devoted to an algorithm due to Aart Johannes Stam for the simulation of the uniform law on the set \\( {\\Pi_n} \\)&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/djalil.chafai.net\/blog\/2012\/05\/03\/generating-uniform-random-partitions\/\">Continue reading<span class=\"screen-reader-text\">Generating uniform random partitions<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":509},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/4836"}],"collection":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/comments?post=4836"}],"version-history":[{"count":36,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/4836\/revisions"}],"predecessor-version":[{"id":7367,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/4836\/revisions\/7367"}],"wp:attachment":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/media?parent=4836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/categories?post=4836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/tags?post=4836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}