Skip to content

Commit 4b57405

Browse files
authored
Update pre-commit (#570)
* Fix Stucchio URL The backslashes are appearing in the actual URL * Update bibtex-tidy * Fix Padonou URL * Increase Node version 15→18 * Run pre-commit autoupdate * Run pre-commit on all files
1 parent 14a7fde commit 4b57405

File tree

79 files changed

+131
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+131
-576
lines changed

Diff for: .pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.3.0
3+
rev: 23.7.0
44
hooks:
55
- id: black-jupyter
66
- repo: https://github.com/nbQA-dev/nbQA
7-
rev: 1.1.0
7+
rev: 1.7.0
88
hooks:
99
- id: nbqa-isort
1010
additional_dependencies: [isort==5.6.4]
1111
- id: nbqa-pyupgrade
1212
additional_dependencies: [pyupgrade==2.7.4]
1313
args: [--py37-plus]
1414
- repo: https://github.com/MarcoGorelli/madforhooks
15-
rev: 0.3.0
15+
rev: 0.4.1
1616
hooks:
1717
- id: check-execution-order
1818
args: [--strict]
@@ -96,7 +96,7 @@ repos:
9696
language: pygrep
9797
types_or: [markdown, rst, jupyter]
9898
- repo: https://github.com/mwouts/jupytext
99-
rev: v1.13.7
99+
rev: v1.15.1
100100
hooks:
101101
- id: jupytext
102102
files: ^examples/.+\.ipynb$

Diff for: examples/case_studies/GEV.myst.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ kernelspec:
1010
name: pymc4-dev
1111
---
1212

13-
+++ {"tags": []}
14-
1513
# Generalized Extreme Value Distribution
1614

1715
:::{post} Sept 27, 2022
@@ -20,7 +18,7 @@ kernelspec:
2018
:author: Colin Caprani
2119
:::
2220

23-
+++ {"tags": []}
21+
+++
2422

2523
## Introduction
2624

@@ -94,8 +92,6 @@ And now set up the model using priors estimated from a quick review of the histo
9492
- $\xi$: we are agnostic to the tail behaviour so centre this at zero, but limit to physically reasonable bounds of $\pm 0.6$, and keep it somewhat tight near zero.
9593

9694
```{code-cell} ipython3
97-
:tags: []
98-
9995
# Optionally centre the data, depending on fitting and divergences
10096
# cdata = (data - data.mean())/data.std()
10197

Diff for: examples/case_studies/Missing_Data_Imputation.ipynb

-2
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,6 @@
19341934
"\n",
19351935
"\n",
19361936
"def make_model(priors, normal_pred_assumption=True):\n",
1937-
"\n",
19381937
" coords = {\n",
19391938
" \"alpha_dim\": [\"lmx_imputed\", \"climate_imputed\", \"empower_imputed\"],\n",
19401939
" \"beta_dim\": [\n",
@@ -8628,7 +8627,6 @@
86288627
"\n",
86298628
"\n",
86308629
"with pm.Model(coords=coords) as hierarchical_model:\n",
8631-
"\n",
86328630
" # Priors\n",
86338631
" company_beta_lmx = pm.Normal(\"company_beta_lmx\", 0, 1)\n",
86348632
" company_beta_male = pm.Normal(\"company_beta_male\", 0, 1)\n",

Diff for: examples/case_studies/Missing_Data_Imputation.myst.md

-2
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ priors = {
426426
427427
428428
def make_model(priors, normal_pred_assumption=True):
429-
430429
coords = {
431430
"alpha_dim": ["lmx_imputed", "climate_imputed", "empower_imputed"],
432431
"beta_dim": [
@@ -707,7 +706,6 @@ coords = {"team": teams, "employee": np.arange(len(df_employee))}
707706
708707
709708
with pm.Model(coords=coords) as hierarchical_model:
710-
711709
# Priors
712710
company_beta_lmx = pm.Normal("company_beta_lmx", 0, 1)
713711
company_beta_male = pm.Normal("company_beta_male", 0, 1)

Diff for: examples/case_studies/bart_heteroscedasticity.myst.md

-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ kernelspec:
2424
In this notebook we show how to use BART to model heteroscedasticity as described in Section 4.1 of [`pymc-bart`](https://github.com/pymc-devs/pymc-bart)'s paper {cite:p}`quiroga2022bart`. We use the `marketing` data set provided by the R package `datarium` {cite:p}`kassambara2019datarium`. The idea is to model a marketing channel contribution to sales as a function of budget.
2525

2626
```{code-cell} ipython3
27-
:tags: []
28-
2927
import os
3028
3129
import arviz as az
@@ -37,8 +35,6 @@ import pymc_bart as pmb
3735
```
3836

3937
```{code-cell} ipython3
40-
:tags: []
41-
4238
%config InlineBackend.figure_format = "retina"
4339
az.style.use("arviz-darkgrid")
4440
plt.rcParams["figure.figsize"] = [10, 6]
@@ -157,8 +153,6 @@ The fit looks good! In fact, we see that the mean and variance increase as a fun
157153
## Watermark
158154

159155
```{code-cell} ipython3
160-
:tags: []
161-
162156
%load_ext watermark
163157
%watermark -n -u -v -iv -w -p pytensor
164158
```

Diff for: examples/case_studies/binning.myst.md

-40
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ Hypothetically we could have used base python, or numpy, to describe the generat
106106
The approach was illustrated with a Gaussian distribution, and below we show a number of worked examples using Gaussian distributions. However, the approach is general, and at the end of the notebook we provide a demonstration that the approach does indeed extend to non-Gaussian distributions.
107107

108108
```{code-cell} ipython3
109-
:tags: []
110-
111109
import warnings
112110
113111
import arviz as az
@@ -219,8 +217,6 @@ We will start by investigating what happens when we use only one set of bins to
219217
### Model specification
220218

221219
```{code-cell} ipython3
222-
:tags: []
223-
224220
with pm.Model() as model1:
225221
sigma = pm.HalfNormal("sigma")
226222
mu = pm.Normal("mu")
@@ -235,8 +231,6 @@ pm.model_to_graphviz(model1)
235231
```
236232

237233
```{code-cell} ipython3
238-
:tags: []
239-
240234
with model1:
241235
trace1 = pm.sample()
242236
```
@@ -248,8 +242,6 @@ Given the posterior values,
248242
we should be able to generate observations that look close to what we observed.
249243

250244
```{code-cell} ipython3
251-
:tags: []
252-
253245
with model1:
254246
ppc = pm.sample_posterior_predictive(trace1)
255247
```
@@ -294,22 +286,16 @@ The more important question is whether we have recovered the parameters of the d
294286
Recall that we used `mu = -2` and `sigma = 2` to generate the data.
295287

296288
```{code-cell} ipython3
297-
:tags: []
298-
299289
az.plot_posterior(trace1, var_names=["mu", "sigma"], ref_val=[true_mu, true_sigma]);
300290
```
301291

302292
Pretty good! And we can access the posterior mean estimates (stored as [xarray](http://xarray.pydata.org/en/stable/index.html) types) as below. The MCMC samples arrive back in a 2D matrix with one dimension for the MCMC chain (`chain`), and one for the sample number (`draw`). We can calculate the overall posterior average with `.mean(dim=["draw", "chain"])`.
303293

304294
```{code-cell} ipython3
305-
:tags: []
306-
307295
trace1.posterior["mu"].mean(dim=["draw", "chain"]).values
308296
```
309297

310298
```{code-cell} ipython3
311-
:tags: []
312-
313299
trace1.posterior["sigma"].mean(dim=["draw", "chain"]).values
314300
```
315301

@@ -324,8 +310,6 @@ Above, we used one set of binned data. Let's see what happens when we swap out f
324310
As with the above, here's the model specification.
325311

326312
```{code-cell} ipython3
327-
:tags: []
328-
329313
with pm.Model() as model2:
330314
sigma = pm.HalfNormal("sigma")
331315
mu = pm.Normal("mu")
@@ -336,15 +320,11 @@ with pm.Model() as model2:
336320
```
337321

338322
```{code-cell} ipython3
339-
:tags: []
340-
341323
with model2:
342324
trace2 = pm.sample()
343325
```
344326

345327
```{code-cell} ipython3
346-
:tags: []
347-
348328
az.plot_trace(trace2);
349329
```
350330

@@ -353,23 +333,17 @@ az.plot_trace(trace2);
353333
Let's run a PPC check to ensure we are generating data that are similar to what we observed.
354334

355335
```{code-cell} ipython3
356-
:tags: []
357-
358336
with model2:
359337
ppc = pm.sample_posterior_predictive(trace2)
360338
```
361339

362340
We calculate the mean bin posterior predictive bin counts, averaged over samples.
363341

364342
```{code-cell} ipython3
365-
:tags: []
366-
367343
ppc.posterior_predictive.counts2.mean(dim=["chain", "draw"]).values
368344
```
369345

370346
```{code-cell} ipython3
371-
:tags: []
372-
373347
c2.values
374348
```
375349

@@ -399,14 +373,10 @@ az.plot_posterior(trace2, var_names=["mu", "sigma"], ref_val=[true_mu, true_sigm
399373
```
400374

401375
```{code-cell} ipython3
402-
:tags: []
403-
404376
trace2.posterior["mu"].mean(dim=["draw", "chain"]).values
405377
```
406378

407379
```{code-cell} ipython3
408-
:tags: []
409-
410380
trace2.posterior["sigma"].mean(dim=["draw", "chain"]).values
411381
```
412382

@@ -419,8 +389,6 @@ Now we need to see what happens if we add in both ways of binning.
419389
### Model Specification
420390

421391
```{code-cell} ipython3
422-
:tags: []
423-
424392
with pm.Model() as model3:
425393
sigma = pm.HalfNormal("sigma")
426394
mu = pm.Normal("mu")
@@ -442,8 +410,6 @@ pm.model_to_graphviz(model3)
442410
```
443411

444412
```{code-cell} ipython3
445-
:tags: []
446-
447413
with model3:
448414
trace3 = pm.sample()
449415
```
@@ -488,20 +454,14 @@ ax[1].set_title("Seven bin discretization of N(-2, 2)")
488454
### Recovering parameters
489455

490456
```{code-cell} ipython3
491-
:tags: []
492-
493457
trace3.posterior["mu"].mean(dim=["draw", "chain"]).values
494458
```
495459

496460
```{code-cell} ipython3
497-
:tags: []
498-
499461
trace3.posterior["sigma"].mean(dim=["draw", "chain"]).values
500462
```
501463

502464
```{code-cell} ipython3
503-
:tags: []
504-
505465
az.plot_posterior(trace3, var_names=["mu", "sigma"], ref_val=[true_mu, true_sigma]);
506466
```
507467

Diff for: examples/case_studies/blackbox_external_likelihood.ipynb

-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@
499499
"source": [
500500
"# define a theano Op for our likelihood function\n",
501501
"class LogLikeWithGrad(tt.Op):\n",
502-
"\n",
503502
" itypes = [tt.dvector] # expects a vector of parameter values when called\n",
504503
" otypes = [tt.dscalar] # outputs a single scalar value (the log likelihood)\n",
505504
"\n",

Diff for: examples/case_studies/blackbox_external_likelihood.myst.md

-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ It's not quite so simple! The `grad()` method itself requires that its inputs ar
423423
```{code-cell} ipython3
424424
# define a theano Op for our likelihood function
425425
class LogLikeWithGrad(tt.Op):
426-
427426
itypes = [tt.dvector] # expects a vector of parameter values when called
428427
otypes = [tt.dscalar] # outputs a single scalar value (the log likelihood)
429428

Diff for: examples/case_studies/blackbox_external_likelihood_numpy.ipynb

-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@
438438
"source": [
439439
"# define a pytensor Op for our likelihood function\n",
440440
"class LogLikeWithGrad(pt.Op):\n",
441-
"\n",
442441
" itypes = [pt.dvector] # expects a vector of parameter values when called\n",
443442
" otypes = [pt.dscalar] # outputs a single scalar value (the log likelihood)\n",
444443
"\n",

Diff for: examples/case_studies/blackbox_external_likelihood_numpy.myst.md

-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ It's not quite so simple! The `grad()` method itself requires that its inputs ar
246246
```{code-cell} ipython3
247247
# define a pytensor Op for our likelihood function
248248
class LogLikeWithGrad(pt.Op):
249-
250249
itypes = [pt.dvector] # expects a vector of parameter values when called
251250
otypes = [pt.dscalar] # outputs a single scalar value (the log likelihood)
252251

Diff for: examples/case_studies/conditional_autoregressive_priors.myst.md

-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ myst:
1313
extra_dependencies: geopandas libpysal
1414
---
1515

16-
+++ {"tags": []}
17-
1816
(conditional_autoregressive_priors)=
1917
# Conditional Autoregressive (CAR) Models for Spatial Data
2018

@@ -82,8 +80,6 @@ except FileNotFoundError:
8280
```
8381

8482
```{code-cell} ipython3
85-
:tags: []
86-
8783
df_scot_cancer.head()
8884
```
8985

Diff for: examples/case_studies/disaster_model.py

-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
year = arange(1851, 1962)
138138

139139
with pm.Model() as model:
140-
141140
switchpoint = pm.DiscreteUniform("switchpoint", lower=year.min(), upper=year.max())
142141
early_mean = pm.Exponential("early_mean", lam=1.0)
143142
late_mean = pm.Exponential("late_mean", lam=1.0)

Diff for: examples/case_studies/disaster_model_theano_op.py

-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def rate_(switchpoint, early_mean, late_mean):
142142

143143

144144
with pm.Model() as model:
145-
146145
# Prior for distribution of switchpoint location
147146
switchpoint = pm.DiscreteUniform("switchpoint", lower=0, upper=years)
148147
# Priors for pre- and post-switch mean number of disasters

Diff for: examples/case_studies/gelman_bioassay.py

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
dose = array([-0.86, -0.3, -0.05, 0.73])
99

1010
with pm.Model() as model:
11-
1211
# Logit-linear model parameters
1312
alpha = pm.Normal("alpha", 0, sigma=100.0)
1413
beta = pm.Normal("beta", 0, sigma=1.0)

Diff for: examples/case_studies/gelman_schools.py

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
sigma = np.array([15, 10, 16, 11, 9, 11, 10, 18])
3232

3333
with Model() as schools:
34-
3534
eta = Normal("eta", 0, 1, shape=J)
3635
mu = Normal("mu", 0, sigma=1e6)
3736
tau = HalfCauchy("tau", 25)

Diff for: examples/case_studies/hierarchical_partial_pooling.ipynb

-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@
155155
"coords = {\"player_names\": player_names.tolist()}\n",
156156
"\n",
157157
"with pm.Model(coords=coords) as baseball_model:\n",
158-
"\n",
159158
" phi = pm.Uniform(\"phi\", lower=0.0, upper=1.0)\n",
160159
"\n",
161160
" kappa_log = pm.Exponential(\"kappa_log\", lam=1.5)\n",
@@ -186,7 +185,6 @@
186185
"outputs": [],
187186
"source": [
188187
"with baseball_model:\n",
189-
"\n",
190188
" theta_new = pm.Beta(\"theta_new\", alpha=phi * kappa, beta=(1.0 - phi) * kappa)\n",
191189
" y_new = pm.Binomial(\"y_new\", n=4, p=theta_new, observed=0)"
192190
]

Diff for: examples/case_studies/hierarchical_partial_pooling.myst.md

-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ player_names = data["FirstName"] + " " + data["LastName"]
9696
coords = {"player_names": player_names.tolist()}
9797
9898
with pm.Model(coords=coords) as baseball_model:
99-
10099
phi = pm.Uniform("phi", lower=0.0, upper=1.0)
101100
102101
kappa_log = pm.Exponential("kappa_log", lam=1.5)
@@ -110,7 +109,6 @@ Recall our original question was with regard to the true batting average for a p
110109

111110
```{code-cell} ipython3
112111
with baseball_model:
113-
114112
theta_new = pm.Beta("theta_new", alpha=phi * kappa, beta=(1.0 - phi) * kappa)
115113
y_new = pm.Binomial("y_new", n=4, p=theta_new, observed=0)
116114
```

0 commit comments

Comments
 (0)