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
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 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
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
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 numpy as np | |
import pymc3 as pm | |
N, T = 20, 10 | |
min_lat, max_lat = 35, 40 | |
min_long, max_long = 30, 35 | |
lat_interval = max_lat - min_lat | |
long_interval = max_long - min_long |
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 geopandas as gpd | |
import numpy as np | |
import pandas as pd | |
import requests | |
save_directory = '../data/' | |
osm_api_url_base = 'http://overpass.openstreetmap.ru/cgi/xapi_meta?' | |
regions = { |
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 pymc3 as pm | |
from pymc3.distributions.transforms import StickBreaking | |
genus_counts = np.random.multinomial(10, np.ones(5)/5, 20) | |
with pm.Model() as model: | |
k = 3 | |
n, p = genus_counts.shape | |
profile_gamma = pm.Gamma('profile_gamma', alpha=np.ones((k, p)), beta=np.ones((k, p)), shape=(k,p)) |
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.step_methods.arraystep import BlockedStep | |
from pymc3.distributions.transforms import stick_breaking | |
from pymc3.model import modelcontext | |
import pymc3 as pm | |
import numpy as np | |
def sample_dirichlet(c): | |
gamma = np.random.gamma(c) | |
p = gamma/gamma.sum(axis=-1, keepdims=True) |
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 | |
from time import time | |
traces = [] | |
t1 = time() | |
with pm.Model() as model: | |
RVS = [] | |
for i in range(20): | |
RVS.append(pm.Normal('var_{0}'.format(i))) |