Skip to content

Instantly share code, notes, and snippets.

@AustinRochford
Created July 31, 2017 13:19
Show Gist options
  • Save AustinRochford/b2287e7e50544f60e8ac811d01dc2ce0 to your computer and use it in GitHub Desktop.
Save AustinRochford/b2287e7e50544f60e8ac811d01dc2ce0 to your computer and use it in GitHub Desktop.
WAIC Multitrace
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pymc3 as pm"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"x = np.random.normal(size=1000)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Auto-assigning NUTS sampler...\n",
"Initializing NUTS using advi+adapt_diag...\n",
"Average Loss = 1,434.5: 5%|▍ | 9687/200000 [00:00<00:13, 13954.09it/s]\n",
"Convergence archived at 10400\n",
"Interrupted at 10,400 [5%]: Average Loss = 1,492.5\n",
"100%|██████████| 1000/1000 [00:00<00:00, 1514.37it/s]\n"
]
}
],
"source": [
"with pm.Model() as model:\n",
" μ = pm.Normal('μ', 0., 10.)\n",
" obs = pm.Normal('obs', μ, 1., observed=x)\n",
" \n",
" trace = pm.sample(njobs=2)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WAIC_r(WAIC=2843.7379152678827, WAIC_se=44.677006148308983, p_WAIC=0.88625793354698179)\n",
"WAIC_r(WAIC=2843.9272891881187, WAIC_se=44.683876069126029, p_WAIC=0.98274948575880394)\n",
"WAIC_r(WAIC=2843.7379152678827, WAIC_se=44.677006148308983, p_WAIC=0.88625793354698179)\n"
]
}
],
"source": [
"with model:\n",
" print(pm.waic(trace))\n",
" print(pm.waic(trace._straces[0]))\n",
" print(pm.waic(trace._straces[1]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment