Skip to content

Commit d3f8f0c

Browse files
Re-run notebooks that don't need human attention (#266)
* Re-run blackbox_external_likelihood_numpy.ipynb notebook * Re-run hierarchical_partial_pooling.ipynb notebook * Don't run pre-commit more often than needed * Re-run item_response_nba.ipynb notebook * Re-run GLM-binomial-regression.ipynb notebook * Re-run GLM-hierarchical.ipynb notebook * Re-run GLM-truncated-censored-regression.ipynb notebook * Re-run sampling_compound_step.ipynb notebook * Re-run MLDA_introduction.ipynb notebook * Re-run MLDA_simple_linear_regression.ipynb notebook
1 parent e927d9e commit d3f8f0c

10 files changed

+1898
-968
lines changed

Diff for: examples/case_studies/blackbox_external_likelihood_numpy.ipynb

+287-95
Large diffs are not rendered by default.

Diff for: examples/case_studies/hierarchical_partial_pooling.ipynb

+240-158
Large diffs are not rendered by default.

Diff for: examples/case_studies/item_response_nba.ipynb

+283-198
Large diffs are not rendered by default.

Diff for: examples/generalized_linear_models/GLM-binomial-regression.ipynb

+206-122
Large diffs are not rendered by default.

Diff for: examples/generalized_linear_models/GLM-hierarchical.ipynb

+281-148
Large diffs are not rendered by default.

Diff for: examples/generalized_linear_models/GLM-truncated-censored-regression.ipynb

+210-64
Large diffs are not rendered by default.

Diff for: examples/pymc3_howto/sampling_compound_step.ipynb

+161-58
Large diffs are not rendered by default.

Diff for: examples/samplers/MLDA_introduction.ipynb

+26-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# MLDA sampler: Introduction and resources\n",
88
"\n",
9-
"This notebook contains an introduction to the Multi-Level Delayed Acceptance MCMC algorithm (MLDA) proposed in [1]. It explains the main idea behind the method, gives an overview of the problems it is good for and points to specific notebooks with examples of how to use it within PyMC3. \n",
9+
"This notebook contains an introduction to the Multi-Level Delayed Acceptance MCMC algorithm (MLDA) proposed in [1]. It explains the main idea behind the method, gives an overview of the problems it is good for and points to specific notebooks with examples of how to use it within PyMC. \n",
1010
"\n",
1111
"[1] Dodwell, Tim & Ketelsen, Chris & Scheichl, Robert & Teckentrup, Aretha. (2019). Multilevel Markov Chain Monte Carlo. SIAM Review. 61. 509-545. https://doi.org/10.1137/19M126966X"
1212
]
@@ -41,15 +41,15 @@
4141
"cell_type": "markdown",
4242
"metadata": {},
4343
"source": [
44-
"### PyMC3 implementation\n",
44+
"### PyMC implementation\n",
4545
"\n",
46-
"MLDA is one of the MCMC inference methods available in PyMC3. You can instantiate an MLDA sampler using the `pm.MLDA(coarse_models=...)`, where you need to pass at least one coarse model within a list.\n",
46+
"MLDA is one of the MCMC inference methods available in PyMC. You can instantiate an MLDA sampler using the `pm.MLDA(coarse_models=...)`, where you need to pass at least one coarse model within a list.\n",
4747
"\n",
48-
"The PyMC3 implementation of MLDA supports any number of levels, tuning parameterization for the bottom-level sampler, separate subsampling rates for each level, choice between blocked and compound sampling for the bottom-level sampler, two types of bottom-level samplers (Metropolis, DEMetropolisZ), adaptive error correction and variance reduction.\n",
48+
"The PyMC implementation of MLDA supports any number of levels, tuning parameterization for the bottom-level sampler, separate subsampling rates for each level, choice between blocked and compound sampling for the bottom-level sampler, two types of bottom-level samplers (Metropolis, DEMetropolisZ), adaptive error correction and variance reduction.\n",
4949
"\n",
5050
"For more details about the MLDA sampler and the way it should be used and parameterised, the user can refer to the docstrings in the code and to the other example notebooks (links below) which deal with more complex problem settings and more advanced MLDA features.\n",
5151
"\n",
52-
"Please note that the MLDA sampler is new in PyMC3. The user should be extra critical about the results and report any problems as issues in the PyMC3's github repository."
52+
"Please note that the MLDA sampler is new in PyMC. The user should be extra critical about the results and report any problems as issues in the PyMC's github repository."
5353
]
5454
},
5555
{
@@ -59,31 +59,41 @@
5959
"### Notebooks with example code\n",
6060
"\n",
6161
"\n",
62-
"[Simple linear regression](./MLDA_simple_linear_regression.ipynb): This notebook demonstrates the workflow for using MLDA within PyMC3. It employes a very simple toy model.\n",
62+
"[Simple linear regression](./MLDA_simple_linear_regression.ipynb): This notebook demonstrates the workflow for using MLDA within PyMC. It employes a very simple toy model.\n",
6363
"\n",
64-
"[Gravity surveying](./MLDA_gravity_surveying.ipynb): In this notebook, we use MLDA to solve a 2-dimensional gravity surveying inverse problem. Evaluating the likelihood requires solving a PDE, which we do using [scipy](https://www.scipy.org/). We also compare the performance of MLDA with other PyMC3 samplers (Metropolis, DEMetropolisZ).\n",
64+
"[Gravity surveying](./MLDA_gravity_surveying.ipynb): In this notebook, we use MLDA to solve a 2-dimensional gravity surveying inverse problem. Evaluating the likelihood requires solving a PDE, which we do using [scipy](https://www.scipy.org/). We also compare the performance of MLDA with other PyMC samplers (Metropolis, DEMetropolisZ).\n",
6565
"\n",
66-
"[Variance reduction 1](./MLDA_variance_reduction_linear_regression.ipynb) and [Variance reduction 2](https://github.com/alan-turing-institute/pymc3/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_variance_reduction_groundwater.ipynb) (external link): Those two notebooks demonstrate the variance reduction feature in a linear regression model and a groundwater flow model. This feature allows the user to define a quantity of interest that they need to estimate using the MCMC samples. It then collects those quantities of interest, as well as differences of these quantities between levels, during MLDA sampling. The collected quentities can then be used to produce an estimate which has lower variance than a standard estimate that uses samples from the fine chain only. The first notebook does not have external dependencies, while the second one requires FEniCS. Note that the second notebook is outside the core PyMC3 repository because FEniCS is not a PyMC3 dependency.\n",
66+
"[Variance reduction 1](./MLDA_variance_reduction_linear_regression.ipynb) and [Variance reduction 2](https://github.com/alan-turing-institute/pymc/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_variance_reduction_groundwater.ipynb) (external link): Those two notebooks demonstrate the variance reduction feature in a linear regression model and a groundwater flow model. This feature allows the user to define a quantity of interest that they need to estimate using the MCMC samples. It then collects those quantities of interest, as well as differences of these quantities between levels, during MLDA sampling. The collected quentities can then be used to produce an estimate which has lower variance than a standard estimate that uses samples from the fine chain only. The first notebook does not have external dependencies, while the second one requires FEniCS. Note that the second notebook is outside the core PyMC repository because FEniCS is not a PyMC dependency.\n",
6767
"\n",
68-
"[Adaptive error model](https://github.com/alan-turing-institute/pymc3/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_adaptive_error_model.ipynb) (external link): In this notebook we use MLDA to tackle another inverse problem; groundwarer flow modeling. The aim is to infer the posterior distribution of model parameters (hydraulic conductivity) given data (measurements of hydraulic head). In this example we make use of Theano Ops in order to define a \"black box\" likelihood, i.e. a likelihood that uses external code. Specifically, our likelihood uses the [FEniCS](https://fenicsproject.org/) library to solve a PDE. This is a common scenario, as PDEs of this type are slow to solve with scipy or other standard libraries. Note that this notebook is outside the core PyMC3 repository because FEniCS is not a PyMC3 dependency. We employ the adaptive error model (AEM) feature and compare the performance of basic MLDA with AEM-enhanced MLDA. The idea of Adaptive Error Model (AEM) is to estimate the mean and variance of the forward-model error between adjacent levels, i.e. estimate the bias of the coarse forward model compared to the fine forward model, and use those estimates to correct the coarse model. Using the technique should improve ESS/sec on the fine level.\n",
68+
"[Adaptive error model](https://github.com/alan-turing-institute/pymc/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_adaptive_error_model.ipynb) (external link): In this notebook we use MLDA to tackle another inverse problem; groundwarer flow modeling. The aim is to infer the posterior distribution of model parameters (hydraulic conductivity) given data (measurements of hydraulic head). In this example we make use of Aesara Ops in order to define a \"black box\" likelihood, i.e. a likelihood that uses external code. Specifically, our likelihood uses the [FEniCS](https://fenicsproject.org/) library to solve a PDE. This is a common scenario, as PDEs of this type are slow to solve with scipy or other standard libraries. Note that this notebook is outside the core PyMC repository because FEniCS is not a PyMC dependency. We employ the adaptive error model (AEM) feature and compare the performance of basic MLDA with AEM-enhanced MLDA. The idea of Adaptive Error Model (AEM) is to estimate the mean and variance of the forward-model error between adjacent levels, i.e. estimate the bias of the coarse forward model compared to the fine forward model, and use those estimates to correct the coarse model. Using the technique should improve ESS/sec on the fine level.\n",
6969
"\n",
70-
"[Benchmarks and tuning](https://github.com/alan-turing-institute/pymc3/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_benchmarks_tuning.ipynb) (external link): In this notebook we benchmark MLDA against other samplers using different parameterizations of the groundwater flow model. We also give some advice on tuning MLDA. Note that this notebook is outside the core PyMC3 repository because FEniCS is not a PyMC3 dependency."
70+
"[Benchmarks and tuning](https://github.com/alan-turing-institute/pymc/blob/mlda_all_notebooks/docs/source/notebooks/MLDA_benchmarks_tuning.ipynb) (external link): In this notebook we benchmark MLDA against other samplers using different parameterizations of the groundwater flow model. We also give some advice on tuning MLDA. Note that this notebook is outside the core PyMC repository because FEniCS is not a PyMC dependency."
7171
]
7272
},
7373
{
7474
"cell_type": "code",
7575
"execution_count": 1,
76-
"metadata": {},
76+
"metadata": {
77+
"execution": {
78+
"iopub.execute_input": "2022-01-09T20:50:25.609487Z",
79+
"iopub.status.busy": "2022-01-09T20:50:25.607489Z",
80+
"iopub.status.idle": "2022-01-09T20:50:25.638235Z",
81+
"shell.execute_reply": "2022-01-09T20:50:25.639236Z"
82+
}
83+
},
7784
"outputs": [
7885
{
7986
"name": "stdout",
8087
"output_type": "stream",
8188
"text": [
82-
"last updated: Sat Oct 10 2020 \n",
89+
"Last updated: Sun Jan 09 2022\n",
90+
"\n",
91+
"Python implementation: CPython\n",
92+
"Python version : 3.8.10\n",
93+
"IPython version : 7.30.1\n",
8394
"\n",
84-
"CPython 3.6.9\n",
85-
"IPython 7.16.1\n",
86-
"watermark 2.0.2\n"
95+
"Watermark: 2.3.0\n",
96+
"\n"
8797
]
8898
}
8999
],
@@ -109,7 +119,7 @@
109119
"name": "python",
110120
"nbconvert_exporter": "python",
111121
"pygments_lexer": "ipython3",
112-
"version": "3.8.5"
122+
"version": "3.8.10"
113123
}
114124
},
115125
"nbformat": 4,

Diff for: examples/samplers/MLDA_simple_linear_regression.ipynb

+203-109
Large diffs are not rendered by default.

Diff for: scripts/rerun.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def run_precommit(fp: pathlib.Path, attempts: int = 2):
6969
_log.info("⏳ Running pre-commit attempt %i on %s", a, fp)
7070
try:
7171
subprocess.check_call(["pre-commit", "run", "--files", str(fp)])
72+
break
7273
except subprocess.CalledProcessError:
7374
if a == attempts - 1:
7475
raise

0 commit comments

Comments
 (0)