8 ms·
Markov chain Monte Carlo without the bullshit (2015)
- credit_guy 4y agoHere's my attempt to explain MCMC in a few paragraphs. Drop a droplet of ink in a glass of water. In time the ink will spread out and after a few minutes it will be homogeneously distributed throughout the whole glass. Why is it so? When it gets to the steady state, you can take any cubic millimeter of water, and any given second there will be as many particles of ink leaving that cube as entering the cube. In other words, each cubic millimeter of water is in balance. What's that got to do with Monte Carlo? Many problems can be reduced to calculating the expected value of a function of a multi-dimensional random variable. All you need to do is take many samples of that variable apply the function, and then take the average. Simple, right? Yes, fairly simple, but how do you draw samples from a multi-dimensional distribution? You pretend you are letting a drop of ink diffuse. You need to make it so that in the steady state, the ink's concentration is the pdf of the distribution you want to draw from. You want to make use of the balance: in each tiny little cube, as many particles of ink enter as they leave. Nobody knows how to enforce this balance. It's too hard: a particle can leave in many ways, and can enter from many places. But when something is hard, sometimes it's simpler to solve a more difficult problem. In this case, you enforce a more stringent condition, called "the detailed balance". You make sure that for any two little cubes, as many particles migrate from one to the other as migrate the opposite way. So, let's say you take point A and point B. The pdf function at the two points has values P(A) and P(B). You have the freedom to choose the transition probabilities P(A->B) and P(B->A). How do you choose them? Well, you enforce the "detailed balance": how many "particles of ink" go from A to B? The number is proportional to the probability of a particle being at A to begin with, and then transitioning from A to B. So, it's P(A)P(A->B). Great. The detailed balance condition is P(A)P(A->B) = P(B)P(B->A). Is there a simple way to get these transition probabilities? Here's a simple example: let's say P(A) is twice as high as P(B). We need to make P(A->B) be just half of P(B->A). We do it in two steps: first we make P(A->B) and P(B->A) equal (for example we draw from the uniform distribution for both) and then we flip a coin, and if it's heads we accept the move from A to B and if it's tails we stay in A. This recipe (called Metropolis) does not work just for P(B)/P(A) = 1/2, but for any ratio (of course you need to use a biased coin). So, that's MCMC. You start from an arbitrary point, draw from the uniform distribution, check the ratio of the probabilities of the end and start point, and if the ratio is less than one, you flip a biased coin and accept the move with the ratio of those probabilities, otherwise stay put. Rinse, repeat. After many steps you end up with a point that's randomly distributed with the target probability. Oh, and there's a bonus. Since the acceptance ratio only depends on the ratio of the pdf at two points, you don't actually need to know the pdf itself, it's ok if you know the pdf up to a normalization constant. Which is exactly the situation when you do Bayesian estimation. That normalization constant is very difficult to calculate (it is itself a multi-dimensional integral). This lucky strike is what allowed Bayesian estimation to exist. Without it, all the field of Bayesian estimation would be just idle speculation.
- blt 4y agoA bit weird to develop everything in terms of a finite probability space. I guess it helps avoid fiddly technical issues of measurability. But we don't want the reader to believe that MCMC only works for finite sets. I think the most famous applications are over uncountable sets. Of course everything is technically finite due to floating-point math, but graph walks don't really capture the spirit of MCMC over finite-precision approximations of continuous probability spaces.
- lucasfcosta 4y agoExcellent piece. I strongly agree that most of the existing literature overcomplicates the subject. It's likely that most technical authors are excellent at the subject they write about, but not good at writing in general. Authors should put themselves in the reader's shoes more often. And no, I'm not saying things should always be simplified. When you write a book you do define an MQR (minimum qualified reader) and write for them. The problem I'm talking about here is that most of the aforementioned content hasn't even defined an MQR or has defined one poorly and is not taking it into account.
- Simon_O_Rourke 4y ago> It's likely that most technical authors are excellent at the subject they write about, but not good at writing in general. Could be that, or it could be that they're keeping things deliberately complex so they have a moat around their own area of specialization.
- larve 4y agoAs I’m about to write a technical book (my first was pretty bad, but sold reasonably well), I found “Write useful books” by Rob Fitzpatrick which approaches writing a “useful” book (i.e., something that really teaches you something) as product design, by basically product-designing your book through multiple beta-reader iterations, really drilling it down on making it useful for the readers. Part of that is cutting down on all the things that impede making progress from applicable piece of knowledge to applicable piece of knowledge such as preface, introduction, long theoretical underpinnings, etc… I think that most textbooks ought to be “useful” books first, rather than a mix of reference material and pedagogy, tediously plodding through things in a sequence that doesn’t make didactic sense.
- abrax3141 4y agoI don’t think that this exposition is any more or less clear than any number of the same in any number of books. Sure, if you just read a 100 word summary, it sounds like the quoted example of “BS”, but any reasonable text also provides an explanation that’s essentially the same thing as the extended explanation given by the author.
- codedokode 4y agoThe article says that we sample random values by walking on a grid. But doesn't it mean that this way the values that we draw will be close to each other? For example, if we have a 2-dimensional grid of size 1000x1000 and make 10 steps, all the values will be close to each other. Doesn't look like a good random sample. Knowledgable people, please explain.
- mdp2021 4y agoFull list of primers from Jeremy Kun (of which the submitted page is one): https://jeremykun.com/primers/ https://jeremykun.com/primers/
- graycat 4y agoThe quote from the article in Encyclopedia of Biostatistics is awash in undefined terminology sometimes about peripheral issues. Clean, logical, all terms well defined and explained, with plenty of advanced content, is in (with some markup using TeX) Erhan \c Cinlar, {\it Introduction to Stochastic Processes,\/} ISBN 0-13-498089-1, Prentice-Hall, Englewood Cliffs, NJ, 1975.\ \ The author was long at Princeton. He is a high quality guy. As I was working my way through grad school in a company working on US national security, a question came up about the survivability of the US SSBN fleet under a special scenario of global nuclear war but limited to sea. Results were wanted in two weeks. So, I drew from Çinlar's book, postulated a Markov process subordinated to a Poisson process, typed some code into a text editor, called a random number generator I'd written in assembler based on the recurrence X(n+1) = X(n) 5^15 + 1 mod 2^47 and was done on time. A famous probabilist was assigned to review my work. His first remark was that there was no way for my software to "fathom" the enormous "state space". I responded, at each time t, the number of SSBNs left is a random variable, finite, with an expectation. So, I generate 500 sample paths, take their average, use the strong law of large numbers, and get an estimate of their expected value within a "gnat's ass" nearly all the time. "The Monte Carlo puts the effort where the action is." The probabilist's remark was "That is a good way to think of it." Need to do some work with Markov chains, simulation, etc.? Right, just read some Çinlar, not much in prerequisites (he omitted measure theory), get clear explanations, no undefined terminology, from first principles to some relatively advanced material, and be successful with your project.
- wuschel 4y agoThank you for the recommendation. The book looks serious to me - it reminds me my math lectures during my chemistry studies in university. How much time would you think does it take to work through it to get some value/insight? Is this even the right material for such endeavour?
- graycat 4y agoFor background, need only some routine calculus and the most elementary probability theory. The chapter on the Poisson process, early in the book, is nice to amazing, e.g., his axiomatic derivation. You should be able to get the main ideas in 1-2 evenings of fun, pleasant reading. Science is awash in Poisson processes; it is nice to understand more about them. That they have no memory seems to me like maybe a thin thread could pull to say some things about what is going on in the internals of some of those cases of Poisson processes. I.e., you are looking at some system with some unknown internals, some working mechanism, but the evidence is that it has no memory. The system has some internal state but no memory? How can that be? So, we have some possibly severe limitations on how the internals work. Now I'm concentrating mostly on my startup and deliberately setting aside pursuing such questions -- maybe later. But you, maybe in chemistry, quantum lifetimes, time until a nucleus splits, ..., glitches in complicated computer systems, .... Similarly for the other chapters. If you take the book fully seriously, e.g., carefully follow all the proofs and work most of the exercises, it's a good one semester course.
- ckrapu 4y agoI like the article. That said, if you are expecting biostatisticians to give the best explanation of the biggest hammer in the Bayesian toolbox, you may be looking in the wrong place. Folks in spatial stats, machine learning, and physics have some really nice introductory material.
- zekrioca 4y agoWould you suggest some?
- nightski 4y agoI'm not so sure about that, Richard McElreath's Statistical Rethinking is an amazing resource.
- 0cf8612b2e1e 4y agoI don’t think Richard would ever describe himself as a statistician? He seems just as frustrated by the bad terminology and convoluted explanations as anyone.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- emehex 4y agoStatistical Rethinking is probably the best textbook that I've ever read. It basically jumped started my career in data!
- deleted 4y ago[deleted]
- emehex 4y agoI love Markov chains! But, I too don't like "terminology, notation, and style of writing in statistics"... so, I built a simple "Rosetta Stone" (Python <> Swift) library implementation of Markov chains here: https://github.com/maxhumber/marc https://github.com/maxhumber/marc
- madrox 4y agoIn the 21st century, statistics has had the odd distinction of being thrust into the spotlight in a way that it never has before in its centuries of existence. Before now, practitioners have mostly been on an island...or more like several islands that are multi-day journeys from each other by rowboat. It's created weird terminology, and even the initiated don't all use the same jargon. I have a degree in statistics, and one thing I learned in school is that if you pick up a textbook the first thing you have to do is figure out its internal terminology. Only the basest concepts or ones named after people tended to use the same names everywhere. I think this is why computer science has been so successful at co-opting a lot of statistic's thunder. It's reorganizing a lot of concepts, and because everyone is interested in the results (image generation, computer vision, etc) it's getting a lot of adoption. Amusingly, I thought that the blurb on MCMC the author quoted was pretty clear. That doesn't happen to me often.
- nerdponx 4y ago> I think this is why computer science has been so successful at co-opting a lot of statistic's thunder. It's reorganizing a lot of concepts, and because everyone is interested in the results (image generation, computer vision, etc) it's getting a lot of adoption. I think it's also that "computer science" can be perceived as having succeeded where statistics failed. And the terminology is frankly a lot more appealing: would you rather "train an AI algorithm", or "fit a model"? Even the recasting of "model" as "algorithm" has a marketing benefit: models have uncertainty and uncertainty is scary, whereas algorithms are perceived as precise and correct.
- shafoshaf 4y agoAs someone who took statistics 30 years ago and promptly forgot most of it, I followed everything except "I want to efficiently draw a name from this distribution". What makes a drawing efficient?
- thehumanmeat 4y agoIf you want to select an integer uniformly random from 0...n-1, you need an expected logn mutually independent random bits. What if you don't want it to be uniformly random, but some other distribution instead? That's where Markov chains help; they use random bits efficiently to draw from an interesting distribution.
- cygaril 4y agoOne possible cost measure is thr number of evaluations of the probability function.
- yxwvut 4y agoComputational efficiency is a major consideration in sampling from a high dimensional distribution. https://en.wikipedia.org/wiki/Rejection_sampling#Drawbacks https://en.wikipedia.org/wiki/Rejection_sampling#Drawbacks
- dxbydt 4y agoLook, if you want to draw from a unit circle, you could enclose the unit circle inside a square. If the center of the unit circle is the origin, it should be clear from some middle school geometry that such a square has upper left cartesian coordinates at (-1,1), bottom right at (1,-1). So its a square of side two. Now you can sample from this square by calling the rand() function twice in any programming language, scaling & translating. So def foo() { -1 + 2*rand() } will do the trick in c/c++/scala/python/whatnot ( I've scaled by two and translated by minus one). So you have your two random variables. Pair them up & that's your tuple (x,y). Now if you make 100 such tuples, not all the tuples will lie inside the unit circle. So you have to toss out the ones that don't. So your drawing isn't 100% efficient. How efficient is it ? Well if you toss out say 21 of those 100, your sampler is 79% efficient. Now where the fuck does the 21 come from ? Well, if you use some high school geometry, unit circle has area pi and that enclosing square has area 4, so pi/4 is approximately 79%, so 100-79 is 21 and so on...So one can construct more efficient samplers for the unit circle by not being so foolish. We should stop enclosing circles in squares & listen to Marsaglia. He died a decade back but before his death he solved the above problem, among others, so we don't waste 21% of our energy. That said, most programs I've seen in banking, data science etc are written by programmers, not statisticians. So they happily use an if statement & reject x% of the samples, so they are super-inefficient. Drawing can be efficient if the statistician codes it up. But that fucker wants to use R, so given the choice between some diehard R fucker & python programmer who can mess around with kubernetes & terraform in their spare time, hapless manager will pick the python programmer everytime, so that's what makes the drawing inefficient. /s tag, but not really. Just speaking from bitter personal experience :)
- yuzzy192 4y agoThis is so useful.
- blitzar 4y agoBe careful - removing the fancy words from "Markov Chain Monte Carlo Simulations" and translating it into English can have a negative effect professionally.
- harry8 4y agoI quite enjoyed McElreath's Statistical Rethinking including on this topic. https://www.youtube.com/watch?v=Qqz5AJjyugM https://www.youtube.com/watch?v=Qqz5AJjyugM
- leecarraher 4y agoRecently watched this on Hamiltonian Monte Carlo, and it was a fantastic primer on the basic concepts and motivations of mcmc, and later hmc https://youtu.be/pHsuIaPbNbY https://youtu.be/pHsuIaPbNbY