This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# given | |
mu_x = 10 | |
mu_y = 20 | |
sigma_x = 2 | |
sigma_y = 3 | |
corr = 0.3 | |
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def extend_datetime_index(index: pd.DatetimeIndex, end: pd.Timestamp = None, periods: int = None) -> pd.DatetimeIndex: | |
""" | |
Minimal function for extending a pandas DateTimeIndex. | |
Original attributes of the `index` (e.g name or tz) are not kept. | |
Only the `freq` attribute is preserved. | |
""" | |
if (bool(end) == bool(periods)): # xor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def neg_binomial_2_rng(mu, phi, size=None): | |
""" | |
RNG for the negative binomial parametrised in terms | |
of the mean and the precision. | |
mean = mu | |
variance = mu + (mu**2)/phi | |
""" | |
tau = np.random.gamma(phi, mu/phi, size=size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conda create -n myenv python=3.6 | |
conda activate myenv | |
pip install ipykernel | |
python -m ipykernel install --user --name myenv --display-name "Python 3.6 (myenv)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
functions { | |
real normalisation(real lam, int lb, int ub) { | |
real result = 0; | |
for (x in lb:ub) { | |
result += (lam^x)/tgamma(x+1); | |
} | |
result *= exp(-lam); | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4.69 | |
5.85 | |
7.28 | |
3.49 | |
3.26 | |
5.69 | |
12.13 | |
10.42 | |
5.28 | |
5.88 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Visualization tools""" | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def spaghetti_plot( | |
x, y, n_samples=20, indices=None, ax=None, plot_kwargs=None | |
): | |
""" | |
Plots x against a few picked examples of y. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python -m pip install --upgrade pip | |
pip install cython pybind11 pythran numpy | |
OPENBLAS=$(brew --prefix openblas) CFLAGS="-falign-functions=8 ${CFLAGS}" pip install --no-use-pep517 scipy==1.7.0 | |
pip install pandas matplotlib jupyter jupyterlab | |
OPENBLAS=$(brew --prefix openblas) CFLAGS="-falign-functions=8 ${CFLAGS}" pip install --no-use-pep517 scikit-learn==1.0.1 | |
jupyter nbextension enable --py widgetsnbextension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Approximate inverse CDF for the poisson distribution in Jax. | |
Based on the approximation method proposed in [1]. | |
References | |
---------- | |
[1]: https://people.maths.ox.ac.uk/gilesm/codes/poissinv/paper.pdf | |
""" | |
import jax | |
import jax.numpy as jnp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pip install matplotlib numpy pandas scipy scikit-learn | |
pip install jax numpyro |
OlderNewer