Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"!date"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Wed Dec 18 13:54:39 PST 2013\r\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import pymc as pm, theano.tensor as T"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"x = array([ 0, 1, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55,\n",
" 60, 65, 70, 75, 80, 85, 90, 95, 100, 105])\n",
"\n",
"y = array([-5.31126213, -6.88284349, -7.28148079, -7.20912457, -6.06006241,\n",
" -5.69987917, -5.72478151, -5.62202549, -5.36570549, -4.96331167,\n",
" -4.50282001, -3.99181652, -3.44459009, -2.88168406, -2.35241652,\n",
" -1.82025242, -1.25903034, -0.66321015, 0.06458783, 0.87678754,\n",
" 1.70916784, 2.56996703, 3.38351035])"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with pm.Model() as m:\n",
" a = pm.Flat('a')\n",
" b = pm.Flat('b')\n",
" c = pm.Flat('c')\n",
" d = pm.Flat('d')\n",
" e = pm.Flat('e')\n",
" f = pm.Flat('f')\n",
" g = pm.Flat('g')\n",
" h = pm.Flat('h')\n",
" \n",
" t1 = a**((x+b)**c)\n",
" t2 = d * T.exp(-e * T.log(x/f)**2)\n",
" t3 = g*h**x\n",
" \n",
" y_pred = t1 + t2 + t3\n",
" y_obs = pm.Normal('y_obs', mu=y_pred/y, sd=1., observed=ones_like(y))"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with m: trace = pm.sample(20000, pm.Metropolis())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [ 2% ] 400 of 20000 complete in 0.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [- 4% ] 822 of 20000 complete in 1.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [--- 7% ] 1593 of 20000 complete in 1.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [---- 11% ] 2391 of 20000 complete in 2.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [------ 15% ] 3195 of 20000 complete in 2.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [------- 20% ] 4014 of 20000 complete in 3.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [--------- 24% ] 4851 of 20000 complete in 3.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [---------- 28% ] 5652 of 20000 complete in 4.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [------------ 32% ] 6431 of 20000 complete in 4.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [------------- 36% ] 7227 of 20000 complete in 5.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [--------------- 40% ] 8011 of 20000 complete in 5.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [---------------- 44% ] 8827 of 20000 complete in 6.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------48% ] 9636 of 20000 complete in 6.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------52% ] 10447 of 20000 complete in 7.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------56%- ] 11246 of 20000 complete in 7.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------60%-- ] 12048 of 20000 complete in 8.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------64%---- ] 12857 of 20000 complete in 8.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------68%------ ] 13689 of 20000 complete in 9.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------72%------- ] 14466 of 20000 complete in 9.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------76%--------- ] 15273 of 20000 complete in 10.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------80%---------- ] 16087 of 20000 complete in 10.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------84%------------ ] 16928 of 20000 complete in 11.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------88%------------- ] 17748 of 20000 complete in 11.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------92%--------------- ] 18574 of 20000 complete in 12.0 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------96%---------------- ] 19380 of 20000 complete in 12.5 sec"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\r",
" [-----------------100%-----------------] 20000 of 20000 complete in 12.9 sec"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"with m: trace = pm.sample(20000, pm.NUTS())"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment