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
def vector_randint(p, axis=1): | |
u = np.random.uniform(size=p.shape) | |
v = u*p | |
return np.argmax(v, axis=axis) | |
def batch_gibbs_sample(parents, children, point, parent_factors, is_observed, extra_factors=None): | |
for var in parents.keys(): | |
should_update = is_observed[:, var] |
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 matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import pymc3 as pm | |
# Define number of entities | |
p = 4 | |
# Define number of obs. per entity | |
n = 6 |
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 pymc3 as pm | |
with pm.Model() as model: | |
x = pm.Normal('x', shape=2) | |
step = pm.NUTS(x) | |
gen = pm.iter_sample(5, step, tune=5, streaming=True) | |
for trace in gen: | |
print(trace) |
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
from pymc3 import ( | |
NUTS, | |
Deterministic, | |
HalfCauchy, | |
Model, | |
MvNormal, | |
find_MAP, | |
sample, | |
summary, | |
traceplot, |
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 | |
import aesara.tensor as at | |
import pymc3 as pm | |
np.random.seed(20090425) | |
n = 1 | |
p = 10 | |
k = 5 | |
t = 200 |
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
## Combined model | |
c_comb = np.asarray([[16,29,4], | |
[16,29,6], | |
[14,30,4], | |
[16,29,3], | |
[16,31,5], | |
[13,29,5], | |
[15,32,5], | |
[15,29,6], | |
[17,31,6], |
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
--------------------------------------------------------------------------- | |
AttributeError Traceback (most recent call last) | |
<ipython-input-5-6e14f40a5c7d> in <module> | |
5 p = pm.Uniform("p", 0, 1) | |
6 pm.Binomial("w", p=p, n=2, observed=1) | |
----> 7 inference_data = pm.sample(500, chains=2, return_inferencedata=True) | |
8 | |
9 assert inference_data | |
~/anaconda3/envs/pymc3-dev-py39/lib/python3.9/site-packages/pymc3-3.11.1-py3.9.egg/pymc3/sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, progressbar, model, random_seed, discard_tuned_samples, compute_convergence_checks, callback, jitter_max_retries, return_inferencedata, idata_kwargs, mp_ctx, pickle_backend, **kwargs) |
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
colors = [ | |
'tab:blue', | |
'tab:orange', | |
'tab:green', | |
'tab:red', | |
'tab:purple', | |
'tab:brown', | |
'tab:pink', | |
'tab:gray', | |
'tab:olive', |
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 enum | |
import numpy as np | |
from mesa import Agent, Model | |
from mesa.time import RandomActivation | |
from mesa.space import MultiGrid | |
from mesa.datacollection import DataCollector | |
from tqdm import tqdm | |
class InfectionModel(Model): |
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 | |
# Run this as a notebook so that the bash cell magic ! works | |
import pandas as pd | |
! wget https://aqs.epa.gov/aqsweb/airdata/daily_44201_2020.zip | |
filepath = './daily_44201_2020.csv' | |
df = pd.read_csv(filepath) |