{"id":43,"date":"2010-05-14T15:52:13","date_gmt":"2010-05-14T13:52:13","guid":{"rendered":"http:\/\/djalil.chafai.net\/blog\/?p=43"},"modified":"2019-11-10T19:09:17","modified_gmt":"2019-11-10T18:09:17","slug":"simulating-heavy-tails","status":"publish","type":"post","link":"https:\/\/djalil.chafai.net\/blog\/2010\/05\/14\/simulating-heavy-tails\/","title":{"rendered":"Simulating heavy tails"},"content":{"rendered":"<p style=\"text-align: justify;\"><a href=\"\/blog\/wp-content\/uploads\/2010\/05\/dilbert-rand.jpg\"><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-1099\" title=\"Dilbert: tour of accounting\" src=\"\/blog\/wp-content\/uploads\/2010\/05\/dilbert-rand-300x113.jpg\" alt=\"\" width=\"300\" height=\"113\" srcset=\"https:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2010\/05\/dilbert-rand-300x113.jpg 300w, https:\/\/djalil.chafai.net\/blog\/wp-content\/uploads\/2010\/05\/dilbert-rand.jpg 680w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a>How to quickly simulate a positive real random variable $X$ with a polynomial tail, say $\\mathbb{P}(X&gt;t)\\sim (1+t)^{-\\alpha}$ as $t\\to\\infty$, for some prescribed $\\alpha&gt;0$. We may use an already coded function provided by\u00a0 our favorite computational software. Quoting my former PhD advisor, <em>you just have to press the button rand or something similar<\/em>. But how to proceed from scratch using uniform random numbers? The inversion method suggests to set $X=U^{-1\/\\alpha}-1$ where $U$ is a uniform random variable on $[0,1].$ The law  of $X$ is Pareto with probability density function $t\\in[0,\\infty)\\mapsto a(1+t)^{-(1+a)}$.\u00a0 It is amusing to remark that the fractional part of $X$ has  probability density function<\/p>\n<p style=\"text-align: justify;\">$$t\\in[0,1]\\mapsto\\alpha\\sum_{n=1}^\\infty\\frac{1}{(n+t)^{1+\\alpha}}=\\alpha\\zeta(\\alpha+1,t+1)$$<\/p>\n<p style=\"text-align: justify;\">where  $\\zeta$ is the <a title=\"Hurwitz Zeta function\" href=\"http:\/\/mathworld.wolfram.com\/HurwitzZetaFunction.html\">Hurwitz  Zeta function<\/a>. The integer part of $X$ follows a Zipf like law.<\/p>\n<p style=\"text-align: justify;\">To simulate an $n$-sample of $X$ with <a title=\"GNU Octave\" href=\"http:\/\/www.octave.org\/\">GNU-Octave<\/a> one can use <em>rand(1,n).^(-1\/alpha)-1<\/em>. The problem is that on computers, real numbers are replaced by\u00a0 <a title=\"Floating point numbers\" href=\"http:\/\/en.wikipedia.org\/wiki\/Floating_point\">floats<\/a>: there is a quantification limit.\u00a0 Small values of $\\alpha$ produce a lack of precision for large values, which are frequent for heavy tails...<\/p>\n<p style=\"text-align: justify;\">Regarding the algorithm, it is not wise to use the inversion method to simulate a law on an infinite set (recall that there is no uniform law of such sets).\u00a0 To simulate $X$, one should prefer an excess packing method as in <a title=\"Ziggurat algorithm for random numbers generation\" href=\"http:\/\/en.wikipedia.org\/wiki\/Ziggurat_algorithm\">Marsaglia &amp; Tsang Ziggurat algorithm<\/a>. This alternative approach has the advantage of being faster and a bit more precise (the code is heavier). It is implemented for exponential, Gaussian, and gamma distributions in the\u00a0 <em>rande<\/em>, <em>randg<\/em>, <em>randn<\/em> functions of GNU-Octave 3.2. If you read French, you may take a look at the first chapter of my <a title=\"Mod\u00e9lisation stochastique et simulation. Cours et applications. Dunod. Math\u00e9matiques appliqu\u00e9es pour le Master. SMAI.\" href=\"\/scripts\/search.php\/?q=Mod%C3%A9lisation+stochastique+et+simulation+ISBN+978-2100513796\">pedagogical book with Bernard Bercu<\/a>. This approach constitutes an instance of\u00a0 a general meta principle in Computer Science which states that one can speed up algorithms by using static pre-computations, related to the rigid structure of the problem. The fastest algorithm is not necessarily the shortest algorithm in terms of number of code lines.<\/p>\n<p style=\"text-align: justify;\">If you are interested in the simulation of $\\alpha$-stable distributions, $0&lt;\\alpha\\leq 2$, you may take a look at the <a title=\"On the Chambers-Mallows-Stuck method for simulating skewed stable random variables\" href=\"http:\/\/www.ams.org\/mathscinet-getitem?mr=1394670\">Chambers-Mallows-Stuck exact algorithm<\/a> which generalizes the well known Box-Muller algorithm for Gaussians (suffers from the quantification limit).<\/p>\n<p style=\"text-align: justify;\">For true (unpredictable) randomness, take a look at <a title=\"random.org - True Random Number Service\" href=\"http:\/\/random.org\/\"><strong>random.org<\/strong><\/a> and its <a title=\"random: an R package for true random numbers\" href=\"http:\/\/cran.r-project.org\/web\/packages\/random\/\"><strong>GNU-R interface<\/strong><\/a> \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to quickly simulate a positive real random variable $X$ with a polynomial tail, say $\\mathbb{P}(X&gt;t)\\sim (1+t)^{-\\alpha}$ as $t\\to\\infty$, for some prescribed $\\alpha&gt;0$. We may&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/djalil.chafai.net\/blog\/2010\/05\/14\/simulating-heavy-tails\/\">Continue reading<span class=\"screen-reader-text\">Simulating heavy tails<\/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":57},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/43"}],"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=43"}],"version-history":[{"count":6,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":11756,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions\/11756"}],"wp:attachment":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}