Path: blob/master/notebooks/book2/12/mcmc_traceplots_unigauss.ipynb
1193 views
Kernel: Python 3.8.12 ('jair')
Visualizing effect of prior on posterior using trace plots and rank plots
author: @karm-patel
Please find numpyro implementation of this notebook here:https://colab.research.google.com/github/probml/pyprobml/blob/master/notebooks/book2/12/mcmc_traceplots_unigauss_numpyro.ipynb
In [1]:
In [2]:
Out[2]:
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
In [3]:
In [4]:
In [5]:
Diffuse prior
In [6]:
In [7]:
In [8]:
Out[8]:
HMCState(position={'alpha': DeviceArray([ 428.515 , 1077.8004 , 163.13783], dtype=float32), 'sigma': DeviceArray([4982.097 , 139.92233, 3284.2356 ], dtype=float32)}, potential_energy=DeviceArray([36.499542, 88.68582 , 35.412888], dtype=float32), potential_energy_grad={'alpha': DeviceArray([0.00046304, 0.11117956, 0.00019339], dtype=float32), 'sigma': DeviceArray([ 4.9846753e-04, -8.3370405e-01, 7.0746709e-04], dtype=float32)})
In [9]:
Out[9]:
DeviceArray([-36.499542, -88.68582 , -35.412888], dtype=float32)
In [10]:
Out[10]:
CPU times: user 4.79 s, sys: 66.1 ms, total: 4.86 s
Wall time: 4.81 s
In [11]:
Out[11]:
Number of divergences (bad prior) = 16
In [12]:
Out[12]:
In [13]:
Out[13]:
alpha:(3, 500)
sigma:(3, 500)
divergence:(3, 500)
In [14]:
Out[14]:
In [15]:
Out[15]:
Senseble prior
In [16]:
In [17]:
In [18]:
Out[18]:
HMCState(position={'alpha': DeviceArray([ 428.515 , 1077.8004 , 163.13783], dtype=float32), 'sigma': DeviceArray([4982.097 , 139.92233, 3284.2356 ], dtype=float32)}, potential_energy=DeviceArray([5918.0366, 6011.6943, 3436.9346], dtype=float32), potential_energy_grad={'alpha': DeviceArray([ 4.2751846, 10.878106 , 1.6214086], dtype=float32), 'sigma': DeviceArray([1.0003985 , 0.16619593, 1.0006075 ], dtype=float32)})
In [19]:
Out[19]:
DeviceArray([-5918.0366, -6011.6943, -3436.9346], dtype=float32)
In [20]:
Out[20]:
CPU times: user 3.57 s, sys: 39.5 ms, total: 3.61 s
Wall time: 3.56 s
In [21]:
Out[21]:
Number of divergences (good prior) = 0
In [22]:
Out[22]:
In [23]:
Out[23]:
alpha:(3, 500)
sigma:(3, 500)
divergence:(3, 500)
In [24]:
Out[24]:
In [25]:
Out[25]:
Latexified Figures
In [26]:
In [53]:
In [54]:
Out[54]:
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying
warnings.warn("LATEXIFY environment variable not set, not latexifying")
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/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 [55]:
Out[55]:
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying
warnings.warn("LATEXIFY environment variable not set, not latexifying")
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/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 [56]:
In [57]:
Out[57]:
/home/patel_karm/anaconda3/envs/py3713/lib/python3.7/site-packages/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying
warnings.warn("LATEXIFY environment variable not set, not latexifying")
In [58]:
Out[58]:
In [ ]: