Skip to content

Instantly share code, notes, and snippets.

@rndpolytope
Last active April 19, 2019 21:38
Show Gist options
  • Save rndpolytope/704fbad70a379e4143d62dcc6b68d592 to your computer and use it in GitHub Desktop.
Save rndpolytope/704fbad70a379e4143d62dcc6b68d592 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import cmdstanpy.model as cmdstan_model"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"cmdstan_model._find_cmdstan(path='~/cmdstan-2.18.1/')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model_1 = cmdstan_model.Model(\"\"\"\n",
"generated quantities {\n",
" vector[10] x;\n",
" for (i in 1:10)\n",
" x[i] = normal_rng(0, 1);\n",
"}\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"fit_1 = model_1.sample(\n",
" algorithm='fixed_param',\n",
" num_warmup=0,\n",
" num_samples=1,\n",
" chains=1,\n",
" seed=1\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'accept_stat__': array([ 0.]),\n",
" 'lp__': array([ 0.]),\n",
" 'x': array([[ 0.511159, -2.02228 , 1.53777 , -0.917215, 1.69472 , -1.39996 ,\n",
" -0.200255, 0.430888, -0.819349, 0.946784]])}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fit_1.csv"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"model_2 = cmdstan_model.Model(\"\"\"\n",
"generated quantities {\n",
" vector[10] x;\n",
" for (i in 1:10)\n",
" x[i] = normal_rng(0, 1);\n",
"}\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"fit_2 = model_1.sample(\n",
" algorithm='fixed_param',\n",
" num_warmup=0,\n",
" num_samples=1,\n",
" chains=1,\n",
" seed=1\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'accept_stat__': array([ 0.]),\n",
" 'lp__': array([ 0.]),\n",
" 'x': array([[-0.00505226, 1.78455 , -2.02283 , -0.297191 , -0.904203 ,\n",
" -1.25453 , -0.0316722 , 0.228872 , 0.718348 , -0.684812 ]])}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fit_2.csv"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/Users/rndpolytope/.cache/cmdstanpy/model-e4c22992', 'id=98540', 'sample', 'algorithm=fixed_param', 'num_warmup=0', 'num_samples=1', 'output', 'file=/var/folders/ly/_ltwkx7n73q9s1xfz8720mvc0000gn/T/tmpycedgg_4/output.csv', 'refresh=1']\n"
]
}
],
"source": [
"print(fit_1.cmd)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/Users/rndpolytope/.cache/cmdstanpy/model-e4c22992', 'id=98540', 'sample', 'algorithm=fixed_param', 'num_warmup=0', 'num_samples=1', 'output', 'file=/var/folders/ly/_ltwkx7n73q9s1xfz8720mvc0000gn/T/tmp6gzzt466/output.csv', 'refresh=1']\n"
]
}
],
"source": [
"print(fit_2.cmd)"
]
}
],
"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.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment