PyMC Implementation of Island Hopper Example

Hello everyone!

I am new to Bayesian inference implementation with pymc3 and require a bit of help with a problem that I am trying to solve.
You may have seen this problem from [Kruschke’s Book]Doing Bayesian Data Analysis) in which he gives an example of a politician visiting a chain of islands to canvas support - being callow, the politician uses a simple rule to determine which island to visit next. Each day, the politician chooses a neighboring island and compares the populations there with the population of the current island. If the neighboring island has a larger population, the politician goes over. If the neighboring island has a smaller population, then the politician visits with probability p=pneighbor/pcurrentp=pneighbor/pcurrent; otherwise the politician stays on the same island. After doing this for many days, the politician will end up spending time on each island proportional to the population of each island - in other words, estimating the distribution of island populations correctly.
I have been following this link to solve this problem via pymc3 library. However, I can’t seem to decide upon the priors and likelihood functions. The above link does not help because they have not used pymc3 to solve the problem.
Any kind of guidance would be highly appreciated.
Thanks

The politician scenario is a much better example of MCMC (and the Metropolis algorithm specifically) than it is of Bayesian inference per se. For example, the scenario doesn’t really include any “data” and thus does not describe any model that could capture the data generating process (i.e., the likelihood). As a consequence, there are no prior beliefs about the unknown/uncertain components of the model (i.e., priors).

But you can apply the Metropolis algorithm to simple inference problems (though you should not use Metropolis for anything other than educational/illustrative purposes). I wrote up this notebook to illustrate exact and approximate approaches to inference in standard a coin-flipping example (Krushke’s Figure 7.4 is similar, but different).

2 Likes

Thank you for the insight into the problem. I realize that it is an MCMC problem instead of a Bayesian inference one because of the lack of a data-generating model. However, is there any way for me to just replicate the same politician problem by using the pymc3 library? I am sorry if this sounds a bit childish but I am still very new to all this and can’t figure out how to map the functions given in this solution to pymc3 functionalities.

I don’t have permission to access that notebook.