Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN blacken first 15 notebooks #4148

Merged
merged 3 commits into from
Oct 5, 2020
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 docs/source/notebooks/AR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"%config InlineBackend.figure_format = 'retina'\n",
"RANDOM_SEED = 8927\n",
"np.random.seed(RANDOM_SEED)\n",
"az.style.use('arviz-darkgrid')"
"az.style.use(\"arviz-darkgrid\")"
]
},
{
Expand Down
66 changes: 37 additions & 29 deletions docs/source/notebooks/BEST.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"import pandas as pd\n",
"import pymc3 as pm\n",
"\n",
"print(f'Running on PyMC3 v{pm.__version__}')"
"print(f\"Running on PyMC3 v{pm.__version__}\")"
]
},
{
Expand All @@ -37,7 +37,7 @@
"outputs": [],
"source": [
"%config InlineBackend.figure_format = 'retina'\n",
"az.style.use('arviz-darkgrid')"
"az.style.use(\"arviz-darkgrid\")"
]
},
{
Expand Down Expand Up @@ -94,18 +94,22 @@
}
],
"source": [
"# fmt: off\n",
"drug = (101,100,102,104,102,97,105,105,98,101,100,123,105,103,100,95,102,106,\n",
" 109,102,82,102,100,102,102,101,102,102,103,103,97,97,103,101,97,104,\n",
" 96,103,124,101,101,100,101,101,104,100,101)\n",
"placebo = (99,101,100,101,102,100,97,101,104,101,102,102,100,105,88,101,100,\n",
" 104,100,100,100,101,102,103,97,101,101,100,101,99,101,100,100,\n",
" 101,100,99,101,100,102,99,100,99)\n",
"# fmt: on\n",
"\n",
"y1 = np.array(drug)\n",
"y2 = np.array(placebo)\n",
"y = pd.DataFrame(dict(value=np.r_[y1, y2], group=np.r_[['drug']*len(drug), ['placebo']*len(placebo)]))\n",
"y = pd.DataFrame(\n",
" dict(value=np.r_[y1, y2], group=np.r_[[\"drug\"] * len(drug), [\"placebo\"] * len(placebo)])\n",
")\n",
"\n",
"y.hist('value', by='group', figsize=(12, 4));"
"y.hist(\"value\", by=\"group\", figsize=(12, 4));"
]
},
{
Expand Down Expand Up @@ -146,8 +150,8 @@
"μ_s = y.value.std() * 2\n",
"\n",
"with pm.Model() as model:\n",
" group1_mean = pm.Normal('group1_mean', mu=μ_m, sd=μ_s)\n",
" group2_mean = pm.Normal('group2_mean', mu=μ_m, sd=μ_s)"
" group1_mean = pm.Normal(\"group1_mean\", mu=μ_m, sd=μ_s)\n",
" group2_mean = pm.Normal(\"group2_mean\", mu=μ_m, sd=μ_s)"
]
},
{
Expand Down Expand Up @@ -176,8 +180,8 @@
"σ_high = 10\n",
"\n",
"with model:\n",
" group1_std = pm.Uniform('group1_std', lower=σ_low, upper=σ_high)\n",
" group2_std = pm.Uniform('group2_std', lower=σ_low, upper=σ_high)"
" group1_std = pm.Uniform(\"group1_std\", lower=σ_low, upper=σ_high)\n",
" group2_std = pm.Uniform(\"group2_std\", lower=σ_low, upper=σ_high)"
]
},
{
Expand Down Expand Up @@ -210,9 +214,9 @@
],
"source": [
"with model:\n",
" ν = pm.Exponential('ν_minus_one', 1/29.) + 1\n",
" ν = pm.Exponential(\"ν_minus_one\", 1 / 29.0) + 1\n",
"\n",
"pm.kdeplot(np.random.exponential(30, size=10000), fill_kwargs={'alpha': 0.5});"
"pm.kdeplot(np.random.exponential(30, size=10000), fill_kwargs={\"alpha\": 0.5});"
]
},
{
Expand All @@ -234,11 +238,11 @@
"outputs": [],
"source": [
"with model:\n",
" λ1 = group1_std**-2\n",
" λ2 = group2_std**-2\n",
" λ1 = group1_std ** -2\n",
" λ2 = group2_std ** -2\n",
"\n",
" group1 = pm.StudentT('drug', nu=ν, mu=group1_mean, lam=λ1, observed=y1)\n",
" group2 = pm.StudentT('placebo', nu=ν, mu=group2_mean, lam=λ2, observed=y2)"
" group1 = pm.StudentT(\"drug\", nu=ν, mu=group1_mean, lam=λ1, observed=y1)\n",
" group2 = pm.StudentT(\"placebo\", nu=ν, mu=group2_mean, lam=λ2, observed=y2)"
]
},
{
Expand All @@ -262,10 +266,11 @@
"outputs": [],
"source": [
"with model:\n",
" diff_of_means = pm.Deterministic('difference of means', group1_mean - group2_mean)\n",
" diff_of_stds = pm.Deterministic('difference of stds', group1_std - group2_std)\n",
" effect_size = pm.Deterministic('effect size', \n",
" diff_of_means / np.sqrt((group1_std**2 + group2_std**2) / 2))"
" diff_of_means = pm.Deterministic(\"difference of means\", group1_mean - group2_mean)\n",
" diff_of_stds = pm.Deterministic(\"difference of stds\", group1_std - group2_std)\n",
" effect_size = pm.Deterministic(\n",
" \"effect size\", diff_of_means / np.sqrt((group1_std ** 2 + group2_std ** 2) / 2)\n",
" )"
]
},
{
Expand Down Expand Up @@ -369,8 +374,11 @@
}
],
"source": [
"pm.plot_posterior(trace, var_names=['group1_mean','group2_mean', 'group1_std', 'group2_std', 'ν_minus_one'],\n",
" color='#87ceeb');"
"pm.plot_posterior(\n",
" trace,\n",
" var_names=[\"group1_mean\", \"group2_mean\", \"group1_std\", \"group2_std\", \"ν_minus_one\"],\n",
" color=\"#87ceeb\",\n",
");"
]
},
{
Expand Down Expand Up @@ -412,9 +420,12 @@
}
],
"source": [
"pm.plot_posterior(trace, var_names=['difference of means','difference of stds', 'effect size'],\n",
" ref_val=0,\n",
" color='#87ceeb');"
"pm.plot_posterior(\n",
" trace,\n",
" var_names=[\"difference of means\", \"difference of stds\", \"effect size\"],\n",
" ref_val=0,\n",
" color=\"#87ceeb\",\n",
");"
]
},
{
Expand Down Expand Up @@ -454,8 +465,7 @@
}
],
"source": [
"pm.forestplot(trace, var_names=['group1_mean',\n",
" 'group2_mean']);"
"pm.forestplot(trace, var_names=[\"group1_mean\", \"group2_mean\"]);"
]
},
{
Expand Down Expand Up @@ -488,9 +498,7 @@
}
],
"source": [
"pm.forestplot(trace, var_names=['group1_std',\n",
" 'group2_std',\n",
" 'ν_minus_one']);"
"pm.forestplot(trace, var_names=[\"group1_std\", \"group2_std\", \"ν_minus_one\"]);"
]
},
{
Expand Down Expand Up @@ -607,7 +615,7 @@
}
],
"source": [
"pm.summary(trace, varnames=['difference of means', 'difference of stds', 'effect size'])"
"pm.summary(trace, varnames=[\"difference of means\", \"difference of stds\", \"effect size\"])"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions docs/source/notebooks/Bayes_factor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@
}
],
"source": [
"BF_smc = np.exp(\n",
" traces[1].report.log_marginal_likelihood - traces[0].report.log_marginal_likelihood\n",
")\n",
"BF_smc = np.exp(traces[1].report.log_marginal_likelihood - traces[0].report.log_marginal_likelihood)\n",
"np.round(BF_smc)"
]
},
Expand Down
Loading