Skip to content

Commit b6f36be

Browse files
committed
2 parents e4a9320 + 46f227c commit b6f36be

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

jupyter/covid-inf-rate/SantaClara_CmdStanPy.ipynb

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "SantaClara_CmdStanPy.ipynb",
77
"provenance": [],
88
"collapsed_sections": [],
9-
"authorship_tag": "ABX9TyNh1NuXuIIVzc5g9FQpoq1m",
9+
"authorship_tag": "ABX9TyN1oagX6vCOD9nEfpF/t/vS",
1010
"include_colab_link": true
1111
},
1212
"kernelspec": {
@@ -373,6 +373,16 @@
373373
"execution_count": 0,
374374
"outputs": []
375375
},
376+
{
377+
"cell_type": "markdown",
378+
"metadata": {
379+
"id": "L1CzZED7FtCS",
380+
"colab_type": "text"
381+
},
382+
"source": [
383+
"In order to avoid divergent iterations, which result in biased estimates, we set the parameter adapt_delta to 0.98. To check the resulting sample, we run CmdStan's `diagnose` utility."
384+
]
385+
},
376386
{
377387
"cell_type": "code",
378388
"metadata": {
@@ -502,13 +512,85 @@
502512
"execution_count": 0,
503513
"outputs": []
504514
},
515+
{
516+
"cell_type": "markdown",
517+
"metadata": {
518+
"id": "vGBOK0c4ekFv",
519+
"colab_type": "text"
520+
},
521+
"source": [
522+
"### Play around with the models and data\n",
523+
"\n",
524+
"If you want to play around with your models and data, you can do so using Colab's `file.upload` utility."
525+
]
526+
},
505527
{
506528
"cell_type": "code",
507529
"metadata": {
508530
"id": "nZh7IS4fl8VM",
509531
"colab_type": "code",
510532
"colab": {}
511533
},
534+
"source": [
535+
"from google.colab import files"
536+
],
537+
"execution_count": 0,
538+
"outputs": []
539+
},
540+
{
541+
"cell_type": "markdown",
542+
"metadata": {
543+
"id": "V38jwvTvfbtQ",
544+
"colab_type": "text"
545+
},
546+
"source": [
547+
"The `files.upload()` function allows you to choose files on your machine to upload. It returns a Python dictionary which is a map of filenames to their contents."
548+
]
549+
},
550+
{
551+
"cell_type": "code",
552+
"metadata": {
553+
"id": "QCjxWPoKfVoE",
554+
"colab_type": "code",
555+
"colab": {}
556+
},
557+
"source": [
558+
"uploaded = files.upload()\n",
559+
"uploaded"
560+
],
561+
"execution_count": 0,
562+
"outputs": []
563+
},
564+
{
565+
"cell_type": "markdown",
566+
"metadata": {
567+
"id": "50vnyQN3gObz",
568+
"colab_type": "text"
569+
},
570+
"source": [
571+
"The uploaded files are also saved into the current working directory, so you can refer to them directly by filename. Therefore, once you've uploaded a new Stan program file, you can use this colab notebook to fit your model to the data."
572+
]
573+
},
574+
{
575+
"cell_type": "code",
576+
"metadata": {
577+
"id": "POhsju4ffld2",
578+
"colab_type": "code",
579+
"colab": {}
580+
},
581+
"source": [
582+
"!ls -lt | head -3"
583+
],
584+
"execution_count": 0,
585+
"outputs": []
586+
},
587+
{
588+
"cell_type": "code",
589+
"metadata": {
590+
"id": "w5zVoY_8gTF7",
591+
"colab_type": "code",
592+
"colab": {}
593+
},
512594
"source": [
513595
""
514596
],

jupyter/covid-inf-rate/SantaClara_CmdStanR.ipynb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,16 @@
350350
"execution_count": 0,
351351
"outputs": []
352352
},
353+
{
354+
"cell_type": "markdown",
355+
"metadata": {
356+
"id": "yWNEf0sdC1Kk",
357+
"colab_type": "text"
358+
},
359+
"source": [
360+
"In order to avoid divergent iterations, which result in biased estimates, we set the parameter `adapt_delta` to 0.98."
361+
]
362+
},
353363
{
354364
"cell_type": "code",
355365
"metadata": {
@@ -359,7 +369,7 @@
359369
},
360370
"source": [
361371
"hier_model <- cmdstan_model(stan_file='hier_sens_spec.stan')\n",
362-
"hier_fit <- hier_model$sample(data='santa_clara_all.data.json')\n"
372+
"hier_fit <- hier_model$sample(data='santa_clara_all.data.json', adapt_delta=0.98)\n"
363373
],
364374
"execution_count": 0,
365375
"outputs": []
@@ -421,7 +431,7 @@
421431
},
422432
"source": [
423433
"hier_model_v2 <- cmdstan_model(stan_file='hier_sens_spec_offset_mult.stan')\n",
424-
"hier_fit_v2 <- hier_model_v2$sample(data='santa_clara_all.data.json')"
434+
"hier_fit_v2 <- hier_model_v2$sample(data='santa_clara_all.data.json', adapt_delta=0.98)"
425435
],
426436
"execution_count": 0,
427437
"outputs": []

0 commit comments

Comments
 (0)