Using Sequential Monte Carlo to compute Bayes factors

Another route to compute Bayes factors is by using a sampling method known as Sequential Monte Carlo (SMC). We are going to learn the details of this method in Chapter 8, Inference Engines. For now, we just need to know that this sampler computes an estimation of the marginal likelihood as a by-product that we can directly use to compute Bayes factors. To use SMC in PyMC3, we just need to pass pm.SMC() to the step argument of sample:

with pm.Model() as model_BF_0:
θ = pm.Beta('θ', 4, 8)
y = pm.Bernoulli('y', θ, observed=y_d)
trace_BF_0 = pm.sample(2500, step=pm.SMC())

with pm.Model() as model_BF_1:
θ = pm.Beta('θ', 8, 4)
y = pm.Bernoulli('y', θ, observed=y_d)
trace_BF_1 = pm.sample(2500, step=pm.SMC())

model_BF_0.marginal_likelihood / model_BF_1.marginal_likelihood

According to the SMC method, the Bayes factor is also around 11. If you want to compute Bayes factors with PyMC3, I strongly recommend using the SMC method. The other method presented in this book is more computationally cumbersome and requires more manual tweaking, mostly because the jumping between models requires more tuning by trial and error by the user. SMC, on the other hand, is a more automated method.

..................Content has been hidden....................

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