{"id":147521,"date":"2024-03-01T04:55:27","date_gmt":"2024-03-01T04:55:27","guid":{"rendered":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/"},"modified":"2025-01-21T12:08:46","modified_gmt":"2025-01-21T12:08:46","slug":"markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c","status":"publish","type":"post","link":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/","title":{"rendered":"Markov Chain Monte Carlo: Made Simple Once and For All"},"content":{"rendered":"<h3 class=\"wp-block-heading\">Data Science<\/h3>\n<p class=\"wp-block-paragraph\">Markov Chain Monte Carlo: Made Simple Once and For All<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"cfd7dd\" data-has-transparency=\"false\" style=\"--dominant-color: #cfd7dd;\" loading=\"lazy\" decoding=\"async\" width=\"2560\" height=\"1707\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\" alt=\"Photo by Karine Avetisyan on Unsplash\" class=\"wp-image-147522 not-transparent\" srcset=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg 2560w, https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-300x200.jpg 300w, https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-1024x683.jpg 1024w, https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-768x512.jpg 768w, https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-1536x1024.jpg 1536w, https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-2048x1365.jpg 2048w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@kar111?utm_source=medium&amp;utm_medium=referral\">Karine Avetisyan<\/a> on <a href=\"https:\/\/unsplash.com?utm_source=medium&amp;utm_medium=referral\">Unsplash<\/a><\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">I recently posted an article where I used Bayesian Inference and Markov chain Monte Carlo (MCMC) to predict the CL round of 16 winners. There, I tried to explain Bayesian statistics in relative depth but I didn&#8217;t tell much about MCMC to avoid making it excessively large. The post:<\/p>\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><a href=\"https:\/\/towardsdatascience.com\/using-bayesian-modeling-to-predict-the-champions-league-8ebb069006ba\"><strong>Using Bayesian Modeling to Predict The Champions League<\/strong><\/a><\/p><\/blockquote>\n<p class=\"wp-block-paragraph\">So I decided to dedicate a full post to introduce Markov Chain Monte Carlo methods for anyone interested in learning how they work mathematically and when they prove to be useful.<\/p>\n<p class=\"wp-block-paragraph\">To tackle this post, I&#8217;ll adopt the divide-and-conquer strategy: divide the term into its simplest terms and explain them individually to then solve the big picture. So this is what we&#8217;ll go through:<\/p>\n<ul class=\"wp-block-list\">\n<li>Monte Carlo methods<\/li>\n<li>Stochastic processes<\/li>\n<li>Markov Chain<\/li>\n<li>MCMC<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">Monte Carlo Methods<\/h3>\n<p class=\"wp-block-paragraph\">A Monte Carlo method or simulation is a type of computational algorithm that consists of using sampling numbers repeatedly to obtain numerical results in the form of the likelihood of a range of results of occurring.<\/p>\n<p class=\"wp-block-paragraph\">In other words, a Monte Carlo simulation is used to estimate or approximate the possible outcomes or distribution of an uncertain event.<\/p>\n<p class=\"wp-block-paragraph\">A simple example to illustrate this is by rolling two dice and adding their values. We could easily compute the probability of each outcome but we could also use Monte Carlo methods to simulate 5,000 dice-rollings (or more) and get the underlying distribution.<\/p>\n<h3 class=\"wp-block-heading\">Stochastic Processes<\/h3>\n<p class=\"wp-block-paragraph\">Wikipedia&#8217;s definition is &quot;A stochastic or random process can be defined as a collection of random variables that is indexed by some mathematical set&quot;[1].<\/p>\n<p class=\"wp-block-paragraph\">In more readable terms: &quot;it&#8217;s any mathematical process that can be modeled with a family of random variables&quot;.[2]<\/p>\n<p class=\"wp-block-paragraph\">Let&#8217;s use a simple example to understand the concept. Imagine you put a video camera on your favorite store to, once every 2 minutes, check how many visitors there are. We define X(0) as the <em>initial state<\/em> and it shows the number of visitors seen at <em>t=0<\/em>. Then, 2 minutes later, we see X(1) and so on.<\/p>\n<p class=\"wp-block-paragraph\">The <em>state space<\/em> is a set of values that our random variables (<em>X(i)<\/em>) can adopt, and they can get from 1 to the maximum store capacity.<\/p>\n<p class=\"wp-block-paragraph\">One of the properties of a stochastic process is that <strong>whatever happens in a specific moment is conditioned to what has happened in the preceding moments<\/strong>. Keeping up with our example, if we have 100 visitors at <em>t=0<\/em>, the probability of having 100 \u00b1 20 at <em>t=1<\/em> is greater than seeing it drop to 10, for example (if no unexpected event happens). Therefore, these X variables aren&#8217;t independent.<\/p>\n<h3 class=\"wp-block-heading\">Markov Chains<\/h3>\n<p class=\"wp-block-paragraph\">A Markov chain is a sequence of numbers where each number is dependent on the previous value of the sequence.<\/p>\n<p class=\"wp-block-paragraph\">So it&#8217;s a stochastic method with one peculiarity: knowing the current state is as good as knowing the entire history. In mathematical terms, we say that a stochastic process is Markovian if X(t+1) conditioned to x(1), x(2),&#8230;x(t) only depends on x(t):<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"888888\" data-has-transparency=\"true\" style=\"--dominant-color: #888888;\" loading=\"lazy\" decoding=\"async\" width=\"537\" height=\"22\" class=\"wp-image-487970 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1dhDb_CFS4CEDS_e7ZXvR1A.gif\" alt=\"Mathematical expression - Image by the author\" \/><figcaption class=\"wp-element-caption\">Mathematical expression &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Keeping up with our example, for it to be considered a Markov chain we would need the number of visitors in a given time &#8211; <em>t &#8211;<\/em> to only depend on the number of visitors we saw in the previous instant &#8211; <em>t-1<\/em>. That&#8217;s not true in real life but imagine it is, then we define the <em><strong>transition probability<\/strong><\/em> as the probability of going from state <em>i<\/em> to state <em>j<\/em> in a specific instant:<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"7f7f7f\" data-has-transparency=\"true\" style=\"--dominant-color: #7f7f7f;\" loading=\"lazy\" decoding=\"async\" width=\"237\" height=\"23\" class=\"wp-image-487971 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1qLOjTthgV-sWGuWbyrsVKg.gif\" alt=\"Transition probability in a Markov chain - Image by the author\" \/><figcaption class=\"wp-element-caption\">Transition probability in a Markov chain &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">And, if that probability is time-independent, we say it&#8217;s <em><strong>stationary<\/strong><\/em>.<\/p>\n<p class=\"wp-block-paragraph\">With this transition probability, we now define the <em><strong>transition matrix<\/strong><\/em>, which is just a matrix with all transition probabilities:<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"808080\" data-has-transparency=\"true\" style=\"--dominant-color: #808080;\" loading=\"lazy\" decoding=\"async\" width=\"209\" height=\"99\" class=\"wp-image-487972 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1ZK1iXSxXhxqBxg-MOrhSDQ.gif\" alt=\"Markovian transition matrix - Image by the author\" \/><figcaption class=\"wp-element-caption\">Markovian transition matrix &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">This matrix comes in handy when we want to compute the probabilities of transitioning from one state to another in <em>n<\/em> steps, which is achieved mathematically with power operations on the matrix:<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"767676\" data-has-transparency=\"true\" style=\"--dominant-color: #767676;\" loading=\"lazy\" decoding=\"async\" width=\"367\" height=\"20\" class=\"wp-image-487973 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1oN3ARrgSIvMZ5v1ao_eg1A.gif\" alt=\"Power operation on the matrix to get transition probability after n steps - Image by the author\" \/><figcaption class=\"wp-element-caption\">Power operation on the matrix to get transition probability after n steps &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Let&#8217;s define now a new &#8211; and dumb &#8211; example, in which we consider that a striker&#8217;s probability of scoring a goal in a football (soccer) match depends only on whether he\/she scored in the previous game or not. Because we suppose it&#8217;s also time-independent &#8211; when the match is played doesn&#8217;t matter &#8211; we are working with stationary transition probabilities.<\/p>\n<p class=\"wp-block-paragraph\">Concretely, if a player scored in the previous match, we assume the probability of scoring again in the next game is 70% (the player is hypermotivated to keep the streak going). If the player doesn&#8217;t score, this probability drops to 40%.<\/p>\n<p class=\"wp-block-paragraph\">Let&#8217;s put that into the transition matrix:<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"6d6d6d\" data-has-transparency=\"true\" style=\"--dominant-color: #6d6d6d;\" loading=\"lazy\" decoding=\"async\" width=\"97\" height=\"44\" class=\"wp-image-487974 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1jLXMVLrSrfArlYXabCTStA.gif\" alt=\"Transition matrix for our example - Image by the author\" \/><figcaption class=\"wp-element-caption\">Transition matrix for our example &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">The proper way to read it is: we have two possible outcomes (goal or no goal). Row 1 defines the next game probabilities for the case in which the player has scored; row 2 does the same but for the case in which he\/she hasn&#8217;t scored. Columns are read similarly: the first one relates to the probabilities of scoring and the second to the probabilities of not scoring.<\/p>\n<p class=\"wp-block-paragraph\">So, for example, 0.7 is the probability of scoring after having scored in the previous game.<\/p>\n<p class=\"wp-block-paragraph\">Now, what are the chances that a certain player scores in the n = 2 game knowing that he hasn&#8217;t scored today?<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"717171\" data-has-transparency=\"true\" style=\"--dominant-color: #717171;\" loading=\"lazy\" decoding=\"async\" width=\"187\" height=\"44\" class=\"wp-image-487975 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1h6zPBRxrNB1FTuNzqupZ0w.gif\" alt=\"Transition matrix for n=2 - Image by the author\" \/><figcaption class=\"wp-element-caption\">Transition matrix for n=2 &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">If the player hasn&#8217;t scored today, we have to focus on the second row. As we&#8217;re interested in the chances of scoring, we focus on the first column. And where these both intersect we have 0.52\u2013the probability of scoring in the game ahead of the next one is 52%.<\/p>\n<p class=\"wp-block-paragraph\">We could want to work out the marginal distributions for each X(t) and we can do it by using the initial conditions in which the chain initialized: X(0).<\/p>\n<p class=\"wp-block-paragraph\">Keeping up with the example, the question would now be: knowing that the player has a 50\u201350% chance of scoring in the first game, what are the chances that he\/she scores then and in the second game ahead of the first?<\/p>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"777777\" data-has-transparency=\"true\" style=\"--dominant-color: #777777;\" loading=\"lazy\" decoding=\"async\" width=\"359\" height=\"44\" class=\"wp-image-487976 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1o5lofcoo30k7lgnM81dkZw.gif\" alt=\"Transition matrix with marginal distributions - Image by the author\" \/><figcaption class=\"wp-element-caption\">Transition matrix with marginal distributions &#8211; Image by the author<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">The answer is 0.565, or 56.5%.<\/p>\n<p class=\"wp-block-paragraph\">What&#8217;s curious about Markov chains is that, independently of which values we choose for p0, we might end up with the same distribution after a certain number of iterations. That&#8217;s called a _<strong>stationary distribution, a<\/strong>_nd this is key for MCMC.<\/p>\n<h3 class=\"wp-block-heading\">Markov Chain Monte Carlo (MCMC)<\/h3>\n<p class=\"wp-block-paragraph\">Now it&#8217;s time to combine both methods together.<\/p>\n<p class=\"wp-block-paragraph\">MCMC methods constitute Monte Carlo simulations where the samples are drawn from random Markov chain sequences to form a probability distribution. In the case of Bayesian modeling, this stationary distribution will be the posterior distribution.<\/p>\n<p class=\"wp-block-paragraph\">Simulating the chain after a given set of steps (what&#8217;s called the <em><strong>burn-in<\/strong><\/em> phase) we&#8217;ll get us to the desired distribution. These simulations are dependent on each other but, if we discard a few after certain iterations, we make sure these simulations are almost independent (<em><strong>thinning<\/strong><\/em>).<\/p>\n<p class=\"wp-block-paragraph\">MCMC comes in handy when we want to perform inference for probability distributions where independent samples from the distribution cannot be easily drawn.<\/p>\n<p class=\"wp-block-paragraph\">Regarding the different MCMC algorithms that exist, we&#8217;ll focus on the two more common ones:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Gibbs Sampling<\/strong>: this algorithm for sampling samples from the conditional distributions. Here, we sample our variables based on the distribution conditional to the other variables and iteratively repeat this process. For example, in a case where we have 3 variables, we would simulate the first one by sampling, for each t in 1&#8230;N iterations:<\/li>\n<\/ul>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"8a8a8a\" data-has-transparency=\"true\" style=\"--dominant-color: #8a8a8a;\" loading=\"lazy\" decoding=\"async\" width=\"192\" height=\"25\" class=\"wp-image-487977 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1gxlQkCLJgX34_ESppNxpRg.gif\" alt=\"Variable update using conditional distribution - Image by the author\" \/><figcaption class=\"wp-element-caption\">Variable update using conditional distribution &#8211; Image by the author<\/figcaption><\/figure>\n<ul class=\"wp-block-list\">\n<li><strong>Metropolis-Hastings<\/strong>: is usually the alternative to Gibbs when simulating the complete conditionals isn&#8217;t possible (i.e. when we cannot sample a variable conditioned to <em>all<\/em> the other ones). This works by proposing a candidate for the next step in the Markov chain &#8211; <strong>x(cand)<\/strong> &#8211; by sampling from a simple distribution &#8211; <strong>q<\/strong> &#8211; built around x(t-1). Then we choose to accept the candidate or not with a determined probability (if it&#8217;s not accepted, then the chain doesn&#8217;t change). This probability is defined by:<\/li>\n<\/ul>\n<figure class=\"wp-block-image size-large\"><img data-dominant-color=\"7c7c7c\" data-has-transparency=\"true\" style=\"--dominant-color: #7c7c7c;\" loading=\"lazy\" decoding=\"async\" width=\"297\" height=\"47\" class=\"wp-image-487978 has-transparency\" src=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/1-Q2A4-d3QCEWMMCbjYk0yw.gif\" alt=\"Acceptance probability in Metropolis-Hastings - Image by the author\" \/><figcaption class=\"wp-element-caption\">Acceptance probability in Metropolis-Hastings &#8211; Image by the author<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n<p class=\"wp-block-paragraph\">In short, MCMC methods consist of drawing random samples conditioned to the previous value\/step only and potentially deciding whether we keep them or not. And repeat multiple times until we form the chains.<\/p>\n<p class=\"wp-block-paragraph\">To schematize, let&#8217;s define the algorithm in a set of steps:<\/p>\n<ol class=\"wp-block-list\">\n<li>Get\/Assign the initial values.<\/li>\n<li>\n<p class=\"wp-block-paragraph\">For each iteration:\na) Sample the candidates from a distribution that only depends on the previous value (Markov Chain).\nb) If we&#8217;re using the Metropolis-Hastings algorithm, decide whether we accept or reject the candidates by computing and using the acceptance probability.\nc) Update\/Store the new values.<\/p>\n<\/li>\n<\/ol>\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">Thanks for reading the post! \n\nI really hope you enjoyed it and found it insightful. There&#039;s a lot more to \ncome, especially more AI-based posts I&#039;m preparing.\n\nFollow me and subscribe to my mail list for more \ncontent like this one, it helps a lot!\n\n@polmarin<\/code><\/pre>\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n<h3 class=\"wp-block-heading\">Resources<\/h3>\n<p class=\"wp-block-paragraph\">[1] Wikipedia contributors. (2024, January 8). Stochastic process. In <em>Wikipedia, The Free Encyclopedia<\/em>. Retrieved 19:43, February 24, 2024, from <a href=\"https:\/\/en.wikipedia.org\/w\/index.php?title=Stochastic_process&amp;oldid=1194369849\">https:\/\/en.wikipedia.org\/w\/index.php?title=Stochastic_process&amp;oldid=1194369849<\/a><\/p>\n<p class=\"wp-block-paragraph\">[2] Christopher Kazakis. (2021, January 8th). See the Future with Stochastic Processes. Retrieved 19:43, February 24, 2024, from <a href=\"https:\/\/towardsdatascience.com\/stochastic-processes-a-beginners-guide-3f42fa9941b5#:~:text=Simply%20put%2C%20a%20stochastic%20process,then%20flip%20it%20exactly%20once.\">https:\/\/towardsdatascience.com\/stochastic-processes-a-beginners-guide-3f42fa9941b5.<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction to MCMC, dividing it into its simplest terms<\/p>\n","protected":false},"author":18,"featured_media":147522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"is_member_only":true,"sub_heading":"Introduction to MCMC, dividing it into its simplest terms","footnotes":""},"categories":[44,14668],"tags":[652,448,703,2698,459],"sponsor":[],"coauthors":[30752],"class_list":["post-147521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science","category-statistics","tag-bayesian-statistics","tag-data-science","tag-markov-chains","tag-monte-carlo-method","tag-statistics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science\" \/>\n<meta property=\"og:description\" content=\"Introduction to MCMC, dividing it into its simplest terms\" \/>\n<meta property=\"og:url\" content=\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\" \/>\n<meta property=\"og:site_name\" content=\"Towards Data Science\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-01T04:55:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-21T12:08:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1707\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Pol Marin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TDataScience\" \/>\n<meta name=\"twitter:site\" content=\"@TDataScience\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pol Marin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\"},\"author\":{\"name\":\"TDS Editors\",\"@id\":\"https:\/\/towardsdatascience.com\/#\/schema\/person\/f9925d336b6fe962b03ad8281d90b8ee\"},\"headline\":\"Markov Chain Monte Carlo: Made Simple Once and For All\",\"datePublished\":\"2024-03-01T04:55:27+00:00\",\"dateModified\":\"2025-01-21T12:08:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\"},\"wordCount\":1563,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/towardsdatascience.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\",\"keywords\":[\"Bayesian Statistics\",\"Data Science\",\"Markov Chains\",\"Monte Carlo Method\",\"Statistics\"],\"articleSection\":[\"Data Science\",\"Statistics\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\",\"url\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\",\"name\":\"Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science\",\"isPartOf\":{\"@id\":\"https:\/\/towardsdatascience.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\",\"datePublished\":\"2024-03-01T04:55:27+00:00\",\"dateModified\":\"2025-01-21T12:08:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage\",\"url\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\",\"contentUrl\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg\",\"width\":2560,\"height\":1707,\"caption\":\"Photo by Karine Avetisyan on Unsplash\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/towardsdatascience.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Markov Chain Monte Carlo: Made Simple Once and For All\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/towardsdatascience.com\/#website\",\"url\":\"https:\/\/towardsdatascience.com\/\",\"name\":\"Towards Data Science\",\"description\":\"Publish AI, ML &amp; data-science insights to a global community of data professionals.\",\"publisher\":{\"@id\":\"https:\/\/towardsdatascience.com\/#organization\"},\"alternateName\":\"TDS\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/towardsdatascience.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/towardsdatascience.com\/#organization\",\"name\":\"Towards Data Science\",\"alternateName\":\"TDS\",\"url\":\"https:\/\/towardsdatascience.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/towardsdatascience.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2025\/02\/tds-logo.jpg\",\"contentUrl\":\"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2025\/02\/tds-logo.jpg\",\"width\":696,\"height\":696,\"caption\":\"Towards Data Science\"},\"image\":{\"@id\":\"https:\/\/towardsdatascience.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/TDataScience\",\"https:\/\/www.youtube.com\/c\/TowardsDataScience\",\"https:\/\/www.linkedin.com\/company\/towards-data-science\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/towardsdatascience.com\/#\/schema\/person\/f9925d336b6fe962b03ad8281d90b8ee\",\"name\":\"TDS Editors\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/towardsdatascience.com\/#\/schema\/person\/image\/23494c9101089ad44ae88ce9d2f56aac\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"TDS Editors\"},\"description\":\"Building a vibrant data science and machine learning community. Share your insights and projects with our global audience: bit.ly\/write-for-tds\",\"url\":\"https:\/\/towardsdatascience.com\/author\/towardsdatascience\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/","og_locale":"en_US","og_type":"article","og_title":"Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science","og_description":"Introduction to MCMC, dividing it into its simplest terms","og_url":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/","og_site_name":"Towards Data Science","article_published_time":"2024-03-01T04:55:27+00:00","article_modified_time":"2025-01-21T12:08:46+00:00","og_image":[{"width":2560,"height":1707,"url":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg","type":"image\/jpeg"}],"author":"Pol Marin","twitter_card":"summary_large_image","twitter_creator":"@TDataScience","twitter_site":"@TDataScience","twitter_misc":{"Written by":"Pol Marin","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#article","isPartOf":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/"},"author":{"name":"TDS Editors","@id":"https:\/\/towardsdatascience.com\/#\/schema\/person\/f9925d336b6fe962b03ad8281d90b8ee"},"headline":"Markov Chain Monte Carlo: Made Simple Once and For All","datePublished":"2024-03-01T04:55:27+00:00","dateModified":"2025-01-21T12:08:46+00:00","mainEntityOfPage":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/"},"wordCount":1563,"commentCount":0,"publisher":{"@id":"https:\/\/towardsdatascience.com\/#organization"},"image":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage"},"thumbnailUrl":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg","keywords":["Bayesian Statistics","Data Science","Markov Chains","Monte Carlo Method","Statistics"],"articleSection":["Data Science","Statistics"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/","url":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/","name":"Markov Chain Monte Carlo: Made Simple Once and For All | Towards Data Science","isPartOf":{"@id":"https:\/\/towardsdatascience.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage"},"image":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage"},"thumbnailUrl":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg","datePublished":"2024-03-01T04:55:27+00:00","dateModified":"2025-01-21T12:08:46+00:00","breadcrumb":{"@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#primaryimage","url":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg","contentUrl":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2024\/03\/0NzII1RX_ekPM8HOb-scaled.jpg","width":2560,"height":1707,"caption":"Photo by Karine Avetisyan on Unsplash"},{"@type":"BreadcrumbList","@id":"https:\/\/towardsdatascience.com\/markov-chain-monte-carlo-made-simple-once-and-for-all-e86e8384186c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/towardsdatascience.com\/"},{"@type":"ListItem","position":2,"name":"Markov Chain Monte Carlo: Made Simple Once and For All"}]},{"@type":"WebSite","@id":"https:\/\/towardsdatascience.com\/#website","url":"https:\/\/towardsdatascience.com\/","name":"Towards Data Science","description":"Publish AI, ML &amp; data-science insights to a global community of data professionals.","publisher":{"@id":"https:\/\/towardsdatascience.com\/#organization"},"alternateName":"TDS","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/towardsdatascience.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/towardsdatascience.com\/#organization","name":"Towards Data Science","alternateName":"TDS","url":"https:\/\/towardsdatascience.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/towardsdatascience.com\/#\/schema\/logo\/image\/","url":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2025\/02\/tds-logo.jpg","contentUrl":"https:\/\/towardsdatascience.com\/wp-content\/uploads\/2025\/02\/tds-logo.jpg","width":696,"height":696,"caption":"Towards Data Science"},"image":{"@id":"https:\/\/towardsdatascience.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/TDataScience","https:\/\/www.youtube.com\/c\/TowardsDataScience","https:\/\/www.linkedin.com\/company\/towards-data-science\/"]},{"@type":"Person","@id":"https:\/\/towardsdatascience.com\/#\/schema\/person\/f9925d336b6fe962b03ad8281d90b8ee","name":"TDS Editors","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/towardsdatascience.com\/#\/schema\/person\/image\/23494c9101089ad44ae88ce9d2f56aac","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"TDS Editors"},"description":"Building a vibrant data science and machine learning community. Share your insights and projects with our global audience: bit.ly\/write-for-tds","url":"https:\/\/towardsdatascience.com\/author\/towardsdatascience\/"}]}},"distributor_meta":false,"distributor_terms":false,"distributor_media":false,"distributor_original_site_name":"Towards Data Science","distributor_original_site_url":"https:\/\/towardsdatascience.com","push-errors":false,"_links":{"self":[{"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/posts\/147521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/comments?post=147521"}],"version-history":[{"count":0,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/posts\/147521\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/media\/147522"}],"wp:attachment":[{"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/media?parent=147521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/categories?post=147521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/tags?post=147521"},{"taxonomy":"sponsor","embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/sponsor?post=147521"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/towardsdatascience.com\/wp-json\/wp\/v2\/coauthors?post=147521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}