@@ -225,6 +225,41 @@ and this will be evident by reading through the markdown and Python notebook cel
225225So don't take my word that these notebooks are safe;
226226review the notebook source code before clicking "RUN ANYWAY" (or "CANCEL").
227227
228+ #### Editing files and data on Colab
229+
230+ The Colab interface provides a "files" utility which lets you upload
231+ data and models in your notebook, and also gives you minimal editing facilities
232+ over files on the Colab instance. This is the file folder icon to the left
233+ of the main window
234+ ``` {r fig11, echo=FALSE, out.width = "75%", fig.cap="Colab Files Utility"}
235+ library(knitr)
236+ include_graphics("img/colab_files_util_1.png")
237+ ```
238+ Clicking on this icon opens the files utility, which shows a view of the files
239+ in the current working directory of the Colab instane. Across the top of
240+ the files utility are controls to upload files from your local computer,
241+ refresh the files view, and connect to your Google Drive.
242+ ``` {r fig12, echo=FALSE, out.width = "75%", fig.cap="Files utility, controls"}
243+ library(knitr)
244+ include_graphics("img/colab_files_util_2.png")
245+ ```
246+ The file upload utility opens a file browser that lets you select one or more files to upload.
247+ ``` {r fig13, echo=FALSE, out.width = "75%", fig.cap="Files utility file browser"}
248+ library(knitr)
249+
250+ include_graphics("img/colab_files_util_3.png")
251+ ```
252+ Once uploaded, Colab provides minimal editing facilities for data and test files.
253+
254+ ``` {r fig15, echo=FALSE, out.width = "75%", fig.cap="Files utility file editor"}
255+ library(knitr)
256+ include_graphics("img/colab_files_util_5.png")
257+ ```
258+ Unfortunately, the extension ` .stan ` is not recognized; however ` .json ` data files
259+ can be edited.
260+ This makes editing program files in Colab challenging.
261+ Fundamentally, Colab is a notebook viewer, not an IDE.
262+
228263
229264### Challenge: Fast Spin-up
230265
@@ -248,23 +283,20 @@ As a Colab VM only persists for at most 12 hours, this means that most of the
248283time your class, talk, or demo will require waiting on this installation process
249284before you or your audience can start running Stan.
250285
251- To avoid this, I created a CmdStan binary for Colab by installing CmdStan on
252- a Colab instance and then making a tar-gzip archive of the resulting compiled executable.
253- Because Google is currently offering limited free storage on the Google Cloud Platform,
254- these CmdStan binaries are stored in a Google storage bucket in the cloud;
255- GitHub would be another way to host them.
256- From a Colab notebook, downloading and unpacking the pre-compiled binaries takes on the order of 10 seconds.
286+ To avoid this, we've created a CmdStan binary for Colab for the CmdStan 2.23.0 release,
287+ [ colab-cmdstan-2.23.0.tar.gz] ( https://github.com/stan-dev/cmdstan/releases/download/v2.23.0/colab-cmdstan-2.23.0.tar.gz ) .
288+ From a Colab notebook, downloading and unpacking this set of pre-compiled binaries takes on the order of 10 seconds.
257289With this shortcut, the Stan install process for Colab consists of three steps:
258290
259291* Install the CmdStanPy or CmdStanR package.
260292* Download the pre-compiled CmdStan binaries for Google Colab.
261- * Register the CmdStan install location in the R or Python session.
293+ * Register the CmdStan install location in the Python or R session.
262294
263295To see how this works, I have created two example notebooks for Colab
264296which run CmdStan's example model ` bernoulli.stan ` :
265- [ CmdStanR_Example_Notebook.ipynb] ( https://github.com/stan-dev/example-models/tree/master/knitr/cloud-compute-2020/CmdStanR_Example_Notebook.ipynb )
266- and
267297[ CmdStanPy_Example_Notebook.ipynb] ( https://github.com/stan-dev/example-models/tree/master/knitr/cloud-compute-2020/CmdStanPy_Example_Notebook.ipynb )
298+ and
299+ [ CmdStanR_Example_Notebook.ipynb] ( https://github.com/stan-dev/example-models/tree/master/knitr/cloud-compute-2020/CmdStanR_Example_Notebook.ipynb )
268300
269301#### CmdStanR notebook spin-up
270302
@@ -301,10 +333,13 @@ set_cmdstan_path("cmdstan-2.23.0")
301333The CmdStanPy_Example_Notebook contains the Python version of the fast spin-up steps.
302334CmdStanPy requires Python3, which is the default runtime for new Colab notebooks.
303335CmdStanPy is a pure-Python package which can be installed from PyPI:
304-
305336```
306- !pip install cmdstanpy
337+ !pip install --update cmdstanpy
307338```
339+ We specify the ` --update ` flag in order to get the latest version,
340+ in case any of the pre-installed Python packages for the Colab Python runtime
341+ are using older versions of CmdStanPy.
342+
308343We can use Python to download and unpack the precompiled CmdStan binaries:
309344```
310345# Install pre-built CmdStan binary
@@ -435,20 +470,13 @@ An extremely interesting Stan notebook would expand the above to the full Bayesi
435470- Repeat the above steps for model 2
436471- Compare the two models
437472
473+ ### Update, May 2020
438474
475+ We've just added notebooks for both Python and R which correspond to Andrew's blogpost on an early
476+ study on Covid-19 prevalence in Santa Clara county, CA:
439477
478+ - https://statmodeling.stat.columbia.edu/2020/05/01/simple-bayesian-analysis-inference-of-coronavirus-infection-rate-from-the-stanford-study-in-santa-clara-county/
440479
480+ The notebooks, models, and data are available from GitHub:
441481
442-
443-
444-
445-
446-
447-
448-
449-
450-
451-
452-
453-
454-
482+ - https://github.com/stan-dev/example-models/tree/master/jupyter/covid-inf-rate
0 commit comments