Skip to content

replace nbqa-black with black-jupyter #224

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

Merged
merged 1 commit into from
Sep 9, 2021
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
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 21.8b0
hooks:
- id: black-jupyter
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.10.0
rev: 1.1.0
hooks:
- id: nbqa-black
additional_dependencies: [black==20.8b1]
- id: nbqa-isort
additional_dependencies: [isort==5.6.4]
- id: nbqa-pyupgrade
Expand Down
15 changes: 5 additions & 10 deletions examples/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
"navbar_end": ["search-field.html", "navbar-icon-links.html"],
"external_links": [
{"name": "Learning", "url": "https://pymc3.readthedocs.io/en/latest/learn.html"},
{"name": "API", "url": "https://pymc3.readthedocs.io/en/latest/api.html"}
]
{"name": "API", "url": "https://pymc3.readthedocs.io/en/latest/api.html"},
],
}

html_favicon = "../_static/PyMC3.ico"
Expand All @@ -103,16 +103,11 @@
# post_auto_excerpt = 2

# MyST config
myst_enable_extensions = [
"colon_fence",
"deflist",
"dollarmath",
"amsmath"
]
myst_enable_extensions = ["colon_fence", "deflist", "dollarmath", "amsmath"]

# bibtex config
bibtex_bibfiles = ['references.bib']
bibtex_default_style = 'unsrt'
bibtex_bibfiles = ["references.bib"]
bibtex_default_style = "unsrt"
bibtex_reference_style = "author_year"

# OpenGraph config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
],
"source": [
"def logp_ab(value):\n",
" \"\"\" prior density\"\"\"\n",
" \"\"\"prior density\"\"\"\n",
" return tt.log(tt.pow(tt.sum(value), -5 / 2))\n",
"\n",
"\n",
Expand Down
4 changes: 1 addition & 3 deletions examples/pymc3_howto/LKJ_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def run(n=1000):
n = 50
with model:
trace = pm.sample(n)
az.plot_trace(
trace, var_names=["mu", "r"]
)
az.plot_trace(trace, var_names=["mu", "r"])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/samplers/SMC-ABC_Lotka-Volterra_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
"\n",
"# Lotka - Volterra equation\n",
"def dX_dt(X, t, a, b, c, d):\n",
" \"\"\" Return the growth rate of fox and rabbit populations. \"\"\"\n",
" \"\"\"Return the growth rate of fox and rabbit populations.\"\"\"\n",
"\n",
" return np.array([a * X[0] - b * X[0] * X[1], -c * X[1] + d * b * X[0] * X[1]])\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/samplers/samplers_mvnormal.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run(steppers, p):
for name in names:
df_effectiven.at[p, name] = rate[name]
df_runtime.at[p, name] = runtime[name]
df_performance.at[p, name] = rate[name] / runtime[name]
df_performance.at[p, name] = rate[name] / runtime[name]

print("\r\nEffective sample size [0...1]")
print(df_effectiven.T.to_string(float_format="{:.3f}".format))
Expand Down
4 changes: 2 additions & 2 deletions examples/survival_analysis/censored_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@
"\n",
"# Helper functions for unimputed censored model\n",
"def left_censored_likelihood(mu, sigma, n_left_censored, lower_bound):\n",
" \"\"\" Likelihood of left-censored data. \"\"\"\n",
" \"\"\"Likelihood of left-censored data.\"\"\"\n",
" return n_left_censored * normal_lcdf(mu, sigma, lower_bound)\n",
"\n",
"\n",
"def right_censored_likelihood(mu, sigma, n_right_censored, upper_bound):\n",
" \"\"\" Likelihood of right-censored data. \"\"\"\n",
" \"\"\"Likelihood of right-censored data.\"\"\"\n",
" return n_right_censored * normal_lccdf(mu, sigma, upper_bound)"
]
},
Expand Down
64 changes: 31 additions & 33 deletions examples/survival_analysis/cox_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"inter1= [ -.01434325, -.01460965, 0, 0, 0, -.01113493, 0, 0, 0, -.0553269, -.03238896, 0, 0, -.07062459, -.07464545, -.07032613, 0, 0, -.01408955, 0, -.00219072, 0, 0, 0, 0, 0, .07300876, .01394272, 0, 0, 0, 0, 0, 0, .05120398, 0, -.00550709, -.02062663, -.03077685, -.01688493, 0, .01149963, 0, .01149963, .01149963, 0, 0, 0, 0, 0, 0, 0, 0, 0, .01149963, .0034338, .0376236, .00733331, 0, .03832785, .03832785, -.02622275, -.02622275, -.02622275, -.01492678, 0, 0, -.02897806, -.02847666, 0, 0, -.04224754, -.04743705, -.0510477, -.031893, 0, 0, 0, -.01503116, .003101, -.00083466, .02395027, -.07952866, 0, 0, -.06586029, 0, -.0613939, -.081205, -.07540084, -.08488011, -.08488011, 0, -.07492433, -.08907269, -.09451609, 0, -.08980743, 0, -.0771635, 0, 0, -.0771635, -.08204606, 0, -.05263504, 0, -.05109092, -.04696729, 0, -.04696729, 0, -.05303248, -.05348096, 0, 0, .00584956, -.00792241, -.01719816, 0, -.01576016, 0, -.04014061, 0, 0, 0, 0, 0, .0471441, 0, .04233112, 0, .04233112, 0, 0, .0493324, .04512087, .03205975, .02913185, 0, .05324252, 0, 0, 0, 0, .05054695, 0, .14026688, .01734403, .06078221, 0, 0, 0, -.03138622, 0, .01637333, 0, 0, 0, 0, .01897239, .01591935, 0, -.0619156, 0, -.06851645, 0, -.03889525, -.05023452, -.05013452, 0, 0, -.01362136, 0, 0, -.02634164, 0, 0, 0, 0, -.00890537, -.00611669, 0, 0, 0, -.01513384, 0, -.03551984, 0, -.01978032, 0, .06706496, .10551275, 0, .03092981, .06556855, 0, 0, 0, .09362991, 0, 0, 0, 0, 0, 0, .02610553, .03546937, 0, 0, .034415, 0, 0, 0, .07546701, 0, 0, 0, 0, -.02919447, -.01016712, 0, 0, 0, 0, -.04845615, -.05010044, 0, 0, 0, 0, 0, 0, -.07666632, 0, 0, -.07226554, -.08216553, -.0777643, 0, 0, -.04727952, 0, -.06870384, -.05999847, 0, 0, 0, .02772475, .02883079, .03642944, 0, .04148949, 0, 0, 0, .04268012, .03225577, 0, -.05140995, -.05399637, 0, 0, .02432223, 0, .0490674, .0490674, .0490674, 0, 0, 0, 0, 0, 0, 0, 0, .10476315, 0, 0, 0, 0, 0, .07008056, 0, 0, .01667466, 0, .05253941, .04293926, 0, .02692172, 0, 0, .08742411, .04533176, 0, .01831875, 0, .09834951, .09952456, 0, .02945534, .038731, 0, .04435538, 0, -.02357505, 0, 0, -.02357505, .09324722, 0, 0, 0, -.03490683, 0, -.05054474, 0, -.0474724, -.04905931, 0, .02879751, 0, 0, 0, 0, 0, 0, 0, .04439012, 0, .02989959, .02989959, .05468828, .04463226, 0, 0, 0, 0, 0, .01231324, -.01399783, .04595331, .00145386, 0, .06459354, -.0007196, 0, -.07614055, -.08435525, 0, -.10299519, 0, 0, 0, -.00210284, -.00797183, 0, 0, 0, 0, -.03545086, 0, 0, 0, 0, -.061286, -.07666647, 0, -.05902354, -.07652324, -.07645561, 0, 0, 0, -.03292062, 0, 0, 0, 0, -.075417, 0, -.07922532, 0, -.08583414, -.07450142, -.08066016, 0, 0, -.06249051, 0, 0, 0, 0, -.0618688, 0, -.06524737, -.04419825, -.04489509, 0, 0, 0, -.04520512, -.04187583, 0, 0, -.03753508, 0, 0, 0, 0, 0, 0, 0, 0, .06862645, 0, 0, -.00120631, .01947345, 0, 0, .03561932, 0, .03158225, .03608047, 0, 0, 0, -.02899643],\n",
"\n",
"inter2= [-.78348798, -.63418788, 0, 0, 0, .11481193, 0, 0, 0, -.88128799, -1.109488, 0, 0, -.30888793, .29651192, -.36688802, 0, 0, -.59088796, 0, .50561196, 0, 0, 0, 0, 0, 2.1662121, .08891205, 0, 0, 0, 0, 0, 0, -.23918791, 0, -.9575879, -.07728811, .29641202, 1.2273121, 0, 1.5764117, 0, .72131211, 1.279212, 0, 0, 0, 0, 0, 0, 0, 0, 0, .36481193, 1.5480118, -.03078791, 1.389112, 0, .70901209, -.16668792, 1.435812, .47001198, 2.0838118, 1.1673121, 0, 0, 1.4470119, .23301201, 0, 0, -.61948794, -.41388795, .263212, .66171199, 0, 0, 0, 1.6920118, 1.334012, 1.2101121, .41591194, -.48498794, 0, 0, .09911207, 0, -.46908805, .0205119, .0535119, -.14228792, -.55708808, 0, -.54008788, -.30998799, -.10958811, 0, -.01338812, 0, -.51788801, 0, 0, .13271193, -.11208793, 0, -.54508799, 0, .16641192, .95871216, 0, 1.6281118, 0, -.49718806, -.41348812, 0, 0, -.11718794, -.57058805, -.59488791, 0, -.65658802, 0, -.52698797, 0, 0, 0, 0, 0, 1.3500118, 0, 1.665812, 0, 1.963912, 0, 0, 1.9371119, .90991193, -.39558789, .39521196, 0, -.05268808, 0, 0, 0, 0, -.12458798, 0, -.28228804, .79281193, -.26358792, 0, 0, 0, -.72828788, 0, .355912, 0, 0, 0, 0, -.43538806, -1.566388, 0, -.28388807, 0, -.69028801, 0, -.78128809, -.54648799, -.92738789, 0, 0, .61571199, 0, 0, 1.012012, 0, 0, 0, 0, .43991187, .9404121, 0, 0, 0, .61671191, 0, 2.6073117, 0, -.60438794, 0, -.18108793, -.48178813, 0, -.22628804, -.07398792, 0, 0, 0, 1.830512, 0, 0, 0, 0, 0, 0, -.36918804, 1.3247118, 0, 0, 1.163012, 0, 0, 0, 1.3241119, 0, 0, 0, 0, -.90038794, -1.250888, 0, 0, 0, 0, -1.048188, -.90138787, 0, 0, 0, 0, 0, 0, -.00878807, 0, 0, .46301201, -.22048803, -.71518797, 0, 0, -.4952881, 0, -.83718795, .57951194, 0, 0, 0, 1.054112, .61721212, 2.2717118, 0, 2.0280118, 0, 0, 0, 2.6503119, 2.3914118, 0, -.36418793, -.9259879, 0, 0, .16971211, 0, 1.9360118, 2.5344119, 2.0171118, 0, 0, 0, 0, 0, 0, 0, 0, .77211195, 0, 0, 0, 0, 0, 1.952312, 0, 0, .25901201, 0, -.5028879, .03641204, 0, .38571194, 0, 0, -.44528791, -.55918807, 0, .39721206, 0, -.34038803, -.05988808, 0, -.03518792, .045512, 0, -.039288, 0, .01431207, 0, 0, .030412, -.31918809, 0, 0, 0, -.324388, 0, -1.232188, 0, -.23678799, -.89188808, 0, -.6766879, 0, 0, 0, 0, 0, 0, 0, -.67818803, 0, 1.099412, 1.2767119, -.64068788, -.50678796, 0, 0, 0, 0, 0, .68371207, .11251191, -.17128797, .17081194, 0, -.48708794, .09591202, 0, -.20108791, -.02158805, 0, -.3012881, 0, 0, 0, -.87638801, -.54488796, 0, 0, 0, 0, -.14738794, 0, 0, 0, 0, -.75718802, -.37418792, 0, 1.0981121, 1.1441121, .47381189, 0, 0, 0, -.33498809, 0, 0, 0, 0, -.91838807, 0, -.34488794, 0, .12971191, .99381214, -.91608804, 0, 0, .98171192, 0, 0, 0, 0, -.01528808, 0, -.41458794, .25691202, .18601207, 0, 0, 0, -.35608789, .79691201, 0, 0, 1.548912, 0, 0, 0, 0, 0, 0, 0, 0, 1.1663117, 0, 0, -.009088, -.49578807, 0, 0, -.2677879, 0, -.25468799, .68631202, 0, 0, 0, -.36198804])\n",
"#fmt: off"
"# fmt: off"
]
},
{
Expand All @@ -149,19 +149,18 @@
"outputs": [],
"source": [
"def load_data_cox(dta):\n",
" array = lambda x : np.array(dta[x], dtype=float)\n",
" t = array('t')\n",
" obs_t = array('obs_t')\n",
" pscenter = array('pscenter')\n",
" hhcenter = array('hhcenter')\n",
" ncomact = array('ncomact')\n",
" rleader = array('rleader')\n",
" dleader = array('dleader')\n",
" inter1 = array('inter1')\n",
" inter2 = array('inter2')\n",
" fail = array('FAIL')\n",
" return (t, obs_t, pscenter, hhcenter, ncomact,\n",
" rleader, dleader, inter1, inter2, fail)"
" array = lambda x: np.array(dta[x], dtype=float)\n",
" t = array(\"t\")\n",
" obs_t = array(\"obs_t\")\n",
" pscenter = array(\"pscenter\")\n",
" hhcenter = array(\"hhcenter\")\n",
" ncomact = array(\"ncomact\")\n",
" rleader = array(\"rleader\")\n",
" dleader = array(\"dleader\")\n",
" inter1 = array(\"inter1\")\n",
" inter2 = array(\"inter2\")\n",
" fail = array(\"FAIL\")\n",
" return (t, obs_t, pscenter, hhcenter, ncomact, rleader, dleader, inter1, inter2, fail)"
]
},
{
Expand All @@ -170,8 +169,7 @@
"metadata": {},
"outputs": [],
"source": [
"(t, obs_t, pscenter, hhcenter, ncomact, rleader,\n",
" dleader, inter1, inter2, fail) = load_data_cox(dta)"
"(t, obs_t, pscenter, hhcenter, ncomact, rleader, dleader, inter1, inter2, fail) = load_data_cox(dta)"
]
},
{
Expand Down Expand Up @@ -210,33 +208,33 @@
"outputs": [],
"source": [
"with Model() as model:\n",
" \n",
"\n",
" T = len(t) - 1\n",
" nsubj = len(obs_t)\n",
"\n",
" # risk set equals one if obs_t >= t\n",
" Y = np.array([[int(obs >= time) for time in t] for obs in obs_t])\n",
" # counting process. jump = 1 if obs_t \\in [t[j], t[j+1])\n",
" dN = np.array([[Y[i,j]*int(t[j+1] >= obs_t[i])*fail[i] for j in range(T)] for i in\n",
" range(nsubj)])\n",
" dN = np.array(\n",
" [[Y[i, j] * int(t[j + 1] >= obs_t[i]) * fail[i] for j in range(T)] for i in range(nsubj)]\n",
" )\n",
"\n",
" c = Gamma(\"c\", 0.0001, 0.00001)\n",
" r = Gamma(\"r\", 0.001, 0.0001)\n",
"\n",
" dL0_star = r * np.diff(t)\n",
"\n",
" c = Gamma('c', .0001, .00001)\n",
" r = Gamma('r', .001, .0001)\n",
" \n",
" dL0_star = r*np.diff(t)\n",
" \n",
" # prior mean hazard\n",
" mu = dL0_star * c \n",
" \n",
" dL0 = Gamma('dL0', mu, c, shape=T)\n",
" mu = dL0_star * c\n",
"\n",
" dL0 = Gamma(\"dL0\", mu, c, shape=T)\n",
"\n",
" beta = Normal('beta', np.zeros(7),\n",
" np.ones(7)*100, shape=7)\n",
" beta = Normal(\"beta\", np.zeros(7), np.ones(7) * 100, shape=7)\n",
"\n",
" linear_model = tt.exp(tt.dot(X.T, beta))\n",
" idt = Y[:, :-1] * tt.outer(linear_model, dL0)\n",
"\n",
" dn_like = Poisson('dn_like', idt, observed=dN)"
" dn_like = Poisson(\"dn_like\", idt, observed=dN)"
]
},
{
Expand Down Expand Up @@ -365,7 +363,7 @@
],
"source": [
"with model:\n",
" trace = sample(2000, n_init=10000, init='advi_map')"
" trace = sample(2000, n_init=10000, init=\"advi_map\")"
]
},
{
Expand All @@ -390,7 +388,7 @@
}
],
"source": [
"az.plot_trace(trace, var_names=['c', 'r']);"
"az.plot_trace(trace, var_names=[\"c\", \"r\"]);"
]
},
{
Expand All @@ -415,7 +413,7 @@
}
],
"source": [
"az.plot_forest(trace, var_names=['beta']);"
"az.plot_forest(trace, var_names=[\"beta\"]);"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/survival_analysis/weibull_aft.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"outputs": [],
"source": [
"def weibull_lccdf(x, alpha, beta):\n",
" \"\"\" Log complementary cdf of Weibull distribution. \"\"\"\n",
" \"\"\"Log complementary cdf of Weibull distribution.\"\"\"\n",
" return -((x / beta) ** alpha)"
]
},
Expand Down Expand Up @@ -595,7 +595,7 @@
"\n",
"\n",
"def gumbel_sf(y, mu, sigma):\n",
" \"\"\" Gumbel survival function. \"\"\"\n",
" \"\"\"Gumbel survival function.\"\"\"\n",
" return 1.0 - tt.exp(-tt.exp(-(y - mu) / sigma))"
]
},
Expand Down
6 changes: 4 additions & 2 deletions scripts/check_toc_is_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
parser.add_argument("paths", nargs="*", type=Path)
args = parser.parse_args()
for path in args.paths:
notebook_name = path.relative_to('examples').with_suffix('').as_posix()
assert notebook_name in toc_keys, f"Notebook '{notebook_name}' not added to table of contents!"
notebook_name = path.relative_to("examples").with_suffix("").as_posix()
assert (
notebook_name in toc_keys
), f"Notebook '{notebook_name}' not added to table of contents!"