Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: nbqa-isort
additional_dependencies: [isort==5.6.4]
- id: nbqa-pyupgrade
additional_dependencies: [pyupgrade==2.7.4]
additional_dependencies: [pyupgrade==3.19.0]
args: [--py37-plus]
- repo: https://github.com/MarcoGorelli/madforhooks
rev: 0.4.1
Expand Down
6 changes: 3 additions & 3 deletions examples/case_studies/factor_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
"source": [
"for i in trace.posterior.chain.values:\n",
" samples = trace.posterior[\"W\"].sel(chain=i, observed_columns=3, latent_columns=1)\n",
" plt.plot(samples, label=\"Chain {}\".format(i + 1))\n",
" plt.plot(samples, label=f\"Chain {i + 1}\")\n",
" plt.axhline(samples.mean(), color=f\"C{i}\")\n",
"plt.legend(ncol=4, loc=\"upper center\", fontsize=12, frameon=True), plt.xlabel(\"Sample\");"
]
Expand Down Expand Up @@ -484,7 +484,7 @@
"\n",
"for i in range(4):\n",
" samples = trace.posterior[\"W\"].sel(chain=i, observed_columns=3, latent_columns=1)\n",
" plt.plot(samples, label=\"Chain {}\".format(i + 1))\n",
" plt.plot(samples, label=f\"Chain {i + 1}\")\n",
"\n",
"plt.legend(ncol=4, loc=\"lower center\", fontsize=8), plt.xlabel(\"Sample\");"
]
Expand Down Expand Up @@ -704,7 +704,7 @@
"\n",
"ax = az.plot_kde(\n",
" trace.posterior[\"W\"].sel(**col_selection).values,\n",
" label=\"MCMC posterior for the explicit model\".format(0),\n",
" label=f\"MCMC posterior for the explicit model\",\n",
" plot_kwargs={\"color\": f\"C{1}\"},\n",
")\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/case_studies/factor_analysis.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ At this point, there are already several warnings regarding failed convergence c
```{code-cell} ipython3
for i in trace.posterior.chain.values:
samples = trace.posterior["W"].sel(chain=i, observed_columns=3, latent_columns=1)
plt.plot(samples, label="Chain {}".format(i + 1))
plt.plot(samples, label=f"Chain {i + 1}")
plt.axhline(samples.mean(), color=f"C{i}")
plt.legend(ncol=4, loc="upper center", fontsize=12, frameon=True), plt.xlabel("Sample");
```
Expand Down Expand Up @@ -198,7 +198,7 @@ with pm.Model(coords=coords) as PPCA_identified:

for i in range(4):
samples = trace.posterior["W"].sel(chain=i, observed_columns=3, latent_columns=1)
plt.plot(samples, label="Chain {}".format(i + 1))
plt.plot(samples, label=f"Chain {i + 1}")

plt.legend(ncol=4, loc="lower center", fontsize=8), plt.xlabel("Sample");
```
Expand Down Expand Up @@ -253,7 +253,7 @@ col_selection = dict(observed_columns=3, latent_columns=1)

ax = az.plot_kde(
trace.posterior["W"].sel(**col_selection).values,
label="MCMC posterior for the explicit model".format(0),
label=f"MCMC posterior for the explicit model",
plot_kwargs={"color": f"C{1}"},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@
" Method = baseline_methods[name]\n",
" method = Method(train)\n",
" baselines[name] = method.rmse(test)\n",
" print(\"{} RMSE:\\t{:.5f}\".format(method, baselines[name]))"
" print(f\"{method} RMSE:\\t{baselines[name]:.5f}\")"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ for name in baseline_methods:
Method = baseline_methods[name]
method = Method(train)
baselines[name] = method.rmse(test)
print("{} RMSE:\t{:.5f}".format(method, baselines[name]))
print(f"{method} RMSE:\t{baselines[name]:.5f}")
```

As expected: the uniform random baseline is the worst by far, the global mean baseline is next best, and the mean of means method is our best baseline. Now let's see how PMF stacks up.
Expand Down
4 changes: 2 additions & 2 deletions examples/gaussian_processes/GP-Heteroskedastic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
" return ℓ_μ, ℓ_σ\n",
"\n",
"\n",
"ℓ_μ, ℓ_σ = [stat for stat in get_ℓ_prior(X_)]"
"ℓ_μ, ℓ_σ = (stat for stat in get_ℓ_prior(X_))"
]
},
{
Expand Down Expand Up @@ -1036,7 +1036,7 @@
" return np.hstack([np.tile(x, (2, 1)), np.vstack([np.zeros(x.shape), np.ones(x.shape)])])\n",
"\n",
"\n",
"Xu_c, X_obs_c, Xnew_c = [add_coreg_idx(x) for x in [Xu, X_obs, Xnew]]\n",
"Xu_c, X_obs_c, Xnew_c = (add_coreg_idx(x) for x in [Xu, X_obs, Xnew])\n",
"\n",
"with pm.Model() as model_htsc:\n",
" ℓ = pm.InverseGamma(\"ℓ\", mu=ℓ_μ, sigma=ℓ_σ)\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/gaussian_processes/GP-Heteroskedastic.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_ℓ_prior(points):
return ℓ_μ, ℓ_σ


ℓ_μ, ℓ_σ = [stat for stat in get_ℓ_prior(X_)]
ℓ_μ, ℓ_σ = (stat for stat in get_ℓ_prior(X_))
```

```{code-cell} ipython3
Expand Down Expand Up @@ -388,7 +388,7 @@ def add_coreg_idx(x):
return np.hstack([np.tile(x, (2, 1)), np.vstack([np.zeros(x.shape), np.ones(x.shape)])])


Xu_c, X_obs_c, Xnew_c = [add_coreg_idx(x) for x in [Xu, X_obs, Xnew]]
Xu_c, X_obs_c, Xnew_c = (add_coreg_idx(x) for x in [Xu, X_obs, Xnew])

with pm.Model() as model_htsc:
ℓ = pm.InverseGamma("ℓ", mu=ℓ_μ, sigma=ℓ_σ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
":::{post} Jan 10, 2023\n",
":tags: generalized linear model, hierarchical model \n",
":category: intermediate\n",
":author: Demetri Pananos, Junpeng Lao, Raúl Maldonado, Farhan Reynaldo\n",
":author: Demetri Pananos, Junpeng Lao, Ra\u00fal Maldonado, Farhan Reynaldo\n",
":::"
]
},
Expand Down Expand Up @@ -203,7 +203,7 @@
"ix_z, ix_x = np.unravel_index(np.argmax(surface, axis=None), surface.shape)\n",
"ax.scatter([X[0, ix_x]], [Z[ix_z, 0]], color=\"red\")\n",
"\n",
"text = r\"$({a},{b})$\".format(a=np.round(X[0, ix_x], 2), b=np.round(Z[ix_z, 0], 2))\n",
"text = rf\"$({np.round(X[0, ix_x], 2)},{np.round(Z[ix_z, 0], 2)})$\"\n",
"\n",
"ax.annotate(\n",
" text,\n",
Expand Down Expand Up @@ -602,7 +602,7 @@
"\n",
".xr-section-summary-in + label:before {\n",
" display: inline-block;\n",
" content: '';\n",
" content: '\u25ba';\n",
" font-size: 11px;\n",
" width: 15px;\n",
" text-align: center;\n",
Expand All @@ -613,7 +613,7 @@
"}\n",
"\n",
".xr-section-summary-in:checked + label:before {\n",
" content: '';\n",
" content: '\u25bc';\n",
"}\n",
"\n",
".xr-section-summary-in:checked + label > span {\n",
Expand Down Expand Up @@ -892,7 +892,7 @@
"## Authors\n",
"\n",
"* Adapted from chapter 5 of Bayesian Data Analysis 3rd Edition {cite:p}`gelman2013bayesian` by Demetri Pananos and Junpeng Lao ([pymc#3054](https://github.com/pymc-devs/pymc/pull/3054))\n",
"* Updated and reexecuted by Raúl Maldonado ([pymc-examples#24](https://github.com/pymc-devs/pymc-examples/pull/24), [pymc-examples#45](https://github.com/pymc-devs/pymc-examples/pull/45) and [pymc-examples#147](https://github.com/pymc-devs/pymc-examples/pull/147))\n",
"* Updated and reexecuted by Ra\u00fal Maldonado ([pymc-examples#24](https://github.com/pymc-devs/pymc-examples/pull/24), [pymc-examples#45](https://github.com/pymc-devs/pymc-examples/pull/45) and [pymc-examples#147](https://github.com/pymc-devs/pymc-examples/pull/147))\n",
"* Updated and reexecuted by Farhan Reynaldo in November 2021 ([pymc-examples#248](https://github.com/pymc-devs/pymc-examples/pull/248))\n",
"* Rerun with PyMC v5, by Reshama Shaikh, January 2023"
]
Expand Down Expand Up @@ -969,4 +969,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ ax.set_ylabel(r"$\log(\alpha+\beta)$", fontsize=16)
ix_z, ix_x = np.unravel_index(np.argmax(surface, axis=None), surface.shape)
ax.scatter([X[0, ix_x]], [Z[ix_z, 0]], color="red")

text = r"$({a},{b})$".format(a=np.round(X[0, ix_x], 2), b=np.round(Z[ix_z, 0], 2))
text = rf"$({np.round(X[0, ix_x], 2)},{np.round(Z[ix_z, 0], 2)})$"

ax.annotate(
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
" columns=[\"id\", \"x\", \"y\", \"sigma_y\", \"sigma_x\", \"rho_xy\"],\n",
")\n",
"\n",
"dfhogg[\"id\"] = dfhogg[\"id\"].apply(lambda x: \"p{}\".format(int(x)))\n",
"dfhogg[\"id\"] = dfhogg[\"id\"].apply(lambda x: f\"p{int(x)}\")\n",
"dfhogg.set_index(\"id\", inplace=True)\n",
"dfhogg.head()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ dfhogg = pd.DataFrame(
columns=["id", "x", "y", "sigma_y", "sigma_x", "rho_xy"],
)

dfhogg["id"] = dfhogg["id"].apply(lambda x: "p{}".format(int(x)))
dfhogg["id"] = dfhogg["id"].apply(lambda x: f"p{int(x)}")
dfhogg.set_index("id", inplace=True)
dfhogg.head()
```
Expand Down
6 changes: 3 additions & 3 deletions examples/ode_models/ODE_with_manual_gradients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
" self._y0 = y0\n",
"\n",
" def simulate(self, parameters, times):\n",
" alpha, beta, gamma, delta, Xt0, Yt0 = [x for x in parameters]\n",
" alpha, beta, gamma, delta, Xt0, Yt0 = (x for x in parameters)\n",
"\n",
" def rhs(y, t, p):\n",
" X, Y = y\n",
Expand Down Expand Up @@ -165,7 +165,7 @@
" return self._simulate(parameters, times, True)\n",
"\n",
" def _simulate(self, parameters, times, sensitivities):\n",
" alpha, beta, gamma, delta, Xt0, Yt0 = [x for x in parameters]\n",
" alpha, beta, gamma, delta, Xt0, Yt0 = (x for x in parameters)\n",
"\n",
" def r(y, t, p):\n",
" X, Y = y\n",
Expand Down Expand Up @@ -951,7 +951,7 @@
" self._times = times\n",
"\n",
" def _simulate(self, parameters, times):\n",
" a, b, c = [float(x) for x in parameters]\n",
" a, b, c = (float(x) for x in parameters)\n",
"\n",
" def rhs(y, t, p):\n",
" V, R = y\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/ode_models/ODE_with_manual_gradients.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LotkaVolterraModel:
self._y0 = y0

def simulate(self, parameters, times):
alpha, beta, gamma, delta, Xt0, Yt0 = [x for x in parameters]
alpha, beta, gamma, delta, Xt0, Yt0 = (x for x in parameters)

def rhs(y, t, p):
X, Y = y
Expand Down Expand Up @@ -133,7 +133,7 @@ class LotkaVolterraModel:
return self._simulate(parameters, times, True)

def _simulate(self, parameters, times, sensitivities):
alpha, beta, gamma, delta, Xt0, Yt0 = [x for x in parameters]
alpha, beta, gamma, delta, Xt0, Yt0 = (x for x in parameters)

def r(y, t, p):
X, Y = y
Expand Down Expand Up @@ -453,7 +453,7 @@ class FitzhughNagumoModel:
self._times = times

def _simulate(self, parameters, times):
a, b, c = [float(x) for x in parameters]
a, b, c = (float(x) for x in parameters)

def rhs(y, t, p):
V, R = y
Expand Down