Exercises

  1. Use the grid approach with other priors; for example, try with prior = (grid <= 0.5).astype(int) or prior = abs(grid - 0.5), or try defining your own crazy priors. Experiment with other data, such as increasing the total amount of data or making it more or less even in terms of the number of heads you observe.
  2. In the code we use to estimate π, keep N fixed and re-run the code a couple of times. Notice that the results are different because we are using random numbers, but also check that the errors are more or less in the same order. Try changing the number of N points and re-run the code. Can you guesstimate how the number of N points and the error are related? For a better estimation, you may want to modify the code to compute the error as a function of N. You can also run the code a few times with the same N and compute the mean error and standard deviation of the error. You can plot these results using the plt.errorbar() function from matplotlib. Try using a set of Ns, such as 100, 1,000, 10,000; that is a difference of one order of magnitude or so.
  3. Modify the func argument you pass to the metropolis function; try using the values of the prior from Chapter 1, Thinking Probabilistically. Compare this code to the grid approach; which part should be modified to be able to use it to solve a Bayesian inference problem?
  1. Compare your answer from the previous exercise to this code by Thomas Wiecki: http://twiecki.github.io/blog/2015/11/10/mcmc-sampling/http://twiecki.github.io/blog/2015/11/10/mcmc-sampling/.
  2. Revisit at least a few of the models from previous chapters and run all the diagnostic tools we saw in this chapter.
  3. Revisit the code from all previous chapters, find those with divergences, and try to reduce the number of them.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.64.66