Skip to content

Instantly share code, notes, and snippets.

View davipatti's full-sized avatar

David Pattinson davipatti

  • UW-Madison
  • New York, USA
View GitHub Profile
@davipatti
davipatti / prior-dists-dont-need-to-resemble-the-posterior.ipynb
Created November 7, 2023 19:21
[Bayesian prior distributions don't need to look like what you think the posterior distribution will look like]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davipatti
davipatti / matplotlib-transforms.py
Last active September 20, 2023 20:54
[Useful matplotlib transforms] #matplotlib
import matplotlib.pyplot as plt
ax = plt.gca()
axis_to_data = ax.transAxes + ax.transData.inverted()
data_to_axis = axis_to_data.inverted()
@davipatti
davipatti / aesara-test.py
Last active June 2, 2023 20:33
[aesara scan IndexError] Using aesara.scan to make values 0 if any three preceding values in a column are non-zero. Output is as expected, but errors are logged, and IndexError gets raised. #aesara
import aesara as ae
import numpy as np
print("aesara version", ae.__version__)
np.random.seed(42)
m, n = 10, 12
arr = np.random.choice([0, 1], p=[0.75, 0.25], size=m * n).reshape(m, n)
print("\ninput:")
@davipatti
davipatti / make_trace.py
Created May 16, 2023 17:42
Try to load a pymc trace from a path. If the path doesn't exist then generate the trace by calling fun.
import arviz as az
def make_trace(path: str, fun: Callable, *args, **kwargs):
"""
Try to load a pymc trace from a path. If the path doesn't exist then generate
the trace by calling fun.
Args:
path: Path to Netcdf file.
fun: Callable that returns a PyMC trace.
@davipatti
davipatti / hide-code-demo.ipynb
Created April 19, 2023 18:04
[ipynb toggle code demo] #jupyter #ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davipatti
davipatti / hide_code_cells.py
Last active April 19, 2023 17:57
[jupyter notebook toggle code cells] Snippet for hiding code cells in a jupyter notebook #jupyter #ipynb #python
from IPython.display import HTML
HTML("""
<script>
code_show = true;
function code_toggle() {
if (code_show) {
$('div.input').hide();
} else {
$('div.input').show();
} code_show = !code_show
@davipatti
davipatti / jupyter-nbconvert-plotly.md
Created March 27, 2023 14:29
[jupyter nbconvert can't export interactive plotly plots from vscode] #vscode #jupyter #nbconvert

Getting this type of error when trying to convert an ipynb containing an interactive plotly figure generated in vscode.

$ jupyter nbconvert test.ipynb
[NbConvertApp] Converting notebook test.ipynb to html
.../pelican-env/lib/python3.11/site-packages/nbconvert/filters/datatypefilter.py:39: UserWarning: Your element with mimetype(s) dict_keys(['application/vnd.plotly.v1+json']) is not able to be represented.
  warn("Your element with mimetype(s) {mimetypes}"
[NbConvertApp] Writing 330169 bytes to test.html
@davipatti
davipatti / html_toc_requirements.txt
Created March 20, 2023 20:55
[jupyter nbconvert html_toc requirements.txt] Magival combination of modules that enables jupyter nbconvert --to html_toc to render a table of contents in my pelican environment. #html_toc #toc #jupyter #nbconvert
aiofiles==22.1.0
aiosqlite==0.18.0
anyio==3.6.2
appnope==0.1.3
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
attrs==22.2.0
Babel==2.12.1
backcall==0.2.0
This file has been truncated, but you can view the full file.
[notice] A new release of pip available: 22.2.2 -> 23.0
[notice] To update, run: pip install --upgrade pip
/var/lib/condor/execute/slot1/dir_3008122/lib.py:15: UserWarning: mfsera not installed
warnings.warn("mfsera not installed")
ERROR (aesara.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (aesara.graph.rewriting.basic): node: Subtensor{int64}(TensorConstant{[ 31 1520]}, ScalarConstant{0})
ERROR (aesara.graph.rewriting.basic): TRACEBACK:
ERROR (aesara.graph.rewriting.basic): Traceback (most recent call last):
File "/var/lib/condor/execute/slot1/dir_3008122/packages/aesara/graph/rewriting/basic.py", line 1933, in process_node
replacements = node_rewriter.transform(fgraph, node)
@davipatti
davipatti / chain0.txt
Created January 19, 2023 21:18
[pymc parameter reporter] A small class for reporting the status of a pymc model, while it samples. #pymc
0 0 a= 1.233 c= 0.036
0 100 a=-0.130 c= 0.014
0 200 a=-0.260 c=-1.752
0 300 a= 1.626 c=-1.839
0 400 a= 0.291 c= 0.438
0 500 a=-0.091 c=-0.126
0 600 a= 0.383 c= 0.046
0 700 a= 0.959 c= 0.280
0 800 a=-1.368 c= 1.264
0 900 a= 0.415 c=-0.102