Path: blob/master/notebooks/book2/12/rhat_slow_mixing_chains.ipynb
1193 views
Kernel: Python [conda env:py3713]
Estimated potential scale reduction ()
author: @karm-patel
In [1]:
We calculate using following equations, which is given in book2, section 11.6.2.2 \begin{align} B &= \frac{N}{M-1} \sum_{m=1}^M (\overline{x}_{\cdot m}
\overline{x}{\cdot \cdot})^2, \text{ where } \overline{x}{\cdot m} = \frac{1}{N} \sum_{n=1}^N x_{nm}, ; ; \overline{x}{\cdot \cdot} = \frac{1}{M} \sum{m=1}^M \overline{x}{\cdot m} &= eq (1) \ W &= \frac{1}{M} \sum{m=1}^M s_m^2, \text{ where } s_m^2 = \frac{1}{N-1} \sum_{n=1}^N (x_{nm}-\overline{x}_{\cdot m})^2 &= eq (2) \ \hat{V}^{+} &= \frac{N-1}{N} W + \frac{1}{N} B &= eq (3) \ \hat{R} &= \sqrt{ \frac{\hat{V}^{+}}{W} } &= eq (4) \end{align}
In [2]:
In [3]:
In [4]:
Out[4]:
/home/patel_karm/probml-utils/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying
warnings.warn("LATEXIFY environment variable not set, not latexifying")
Bimodal distribution
we will take samples from bimodal distribution using HMC algorithm
In [5]:
Out[5]:
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
/home/patel_karm/probml-utils/probml_utils/plotting.py:80: UserWarning: set FIG_DIR environment variable to save figures
warnings.warn("set FIG_DIR environment variable to save figures")
Stationary chains but not mixing up
In [6]:
In [7]:
In [8]:
Out[8]:
HMCState(position=DeviceArray([-5., 5.], dtype=float32), potential_energy=DeviceArray([2.2397728, 2.2397728], dtype=float32), potential_energy_grad=DeviceArray([-0.44444442, 0.44444442], dtype=float32))
In [9]:
In [10]:
Out[10]:
B=17303.185546875
W=1.6774184703826904
v_plus=18.978925704956055
In [11]:
Out[11]:
/home/patel_karm/probml-utils/probml_utils/plotting.py:80: UserWarning: set FIG_DIR environment variable to save figures
warnings.warn("set FIG_DIR environment variable to save figures")
In [12]:
Out[12]:
In [13]:
Out[13]:
Mixing chains but non stationary
In [14]:
In [15]:
Out[15]:
HMCState(position=DeviceArray([-4., 4.], dtype=float32), potential_energy=DeviceArray([2.0175502, 2.0175502], dtype=float32), potential_energy_grad=DeviceArray([-2.3674133e-06, 2.3674133e-06], dtype=float32))
In [16]:
In [17]:
Out[17]:
B=83.5451431274414
W=10.955224990844727
v_plus=11.027814865112305
In [18]:
Out[18]:
/home/patel_karm/probml-utils/probml_utils/plotting.py:80: UserWarning: set FIG_DIR environment variable to save figures
warnings.warn("set FIG_DIR environment variable to save figures")
In [19]:
Out[19]:
In [20]:
Out[20]:
In [ ]: