Path: blob/master/notebooks/book2/inf/hmc_beta_binom.ipynb
1192 views
Kernel: Python [conda env:py3713]
Hamiltonian Monte Carlo (HMC) approximation for beta-bernouli model
author: @karm-patel
In this notebook, we approximate posterior of beta-bernouli model using HMC approximation. HMC is markov chain monte carlo (MCMC) algorithm.
In [1]:
In [2]:
In [3]:
Dataset
In [4]:
Out[4]:
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
Prior, Likelihood, and True Posterior
For coin toss problem, since we know the closed form solution of posterior, we compare the distributions of Prior, Likelihood, and True Posterior below.
In [5]:
Out[5]:
NUTS using Blackjax
Reference: https://blackjax-devs.github.io/blackjax/examples/Introduction.html
In [70]:
In [100]:
In [101]:
In [102]:
Out[102]:
CPU times: user 3.24 s, sys: 74 ms, total: 3.32 s
Wall time: 3.26 s
In [103]:
In [104]:
Out[104]:
(1000, 4)
In [105]:
Out[105]:
In [106]:
Out[106]:
Change of variable
In [137]:
In [138]:
In [139]:
In [140]:
Out[140]:
CPU times: user 4.7 s, sys: 18.4 ms, total: 4.72 s
Wall time: 4.66 s
In [141]:
In [142]:
In [143]:
Out[143]:
(1100, 4)
In [144]:
Out[144]:
In [145]:
Out[145]:
In [146]:
Out[146]:
0.15384615384615385
In [149]:
Out[149]:
In [ ]: