This file contains hidden or 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 os | |
| os.environ['THEANO_FLAGS'] = 'device=cuda,floatX=float64' | |
| import pymc3 as pm | |
| with pm.Model(): | |
| x = pm.Normal('x', shape=1000) | |
| trace = pm.sample(chains=1, cores=1) |
This file contains hidden or 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 theano | |
| from theano import function, config, shared, tensor as tt | |
| import numpy | |
| import time | |
| vlen = 10 * 30 * 768 # 10 x #cores x # threads per core | |
| iters = 1000 | |
| rng = numpy.random.RandomState(22) | |
| x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) |
This file contains hidden or 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 | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import arviz as az | |
| from pymc3.step_methods.arraystep import BlockedStep | |
| b = [2,1.5] | |
| sigma = 2 |
This file contains hidden or 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 arviz as az | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| import pymc3 as pm | |
| from pymc3.step_methods.arraystep import BlockedStep | |
| # ### Create simulated data under linear regression model |
This file contains hidden or 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
| Y = xr.DataArray(Y_raw, dims=('observed_columns','rows')) | |
| Y = Y.assign_coords({'observed_columns':np.arange(d),'rows':np.arange(n)}) | |
| def post_hoc_fun(W, psi, Y, rng=None): | |
| ''' | |
| Recovers latent variables given observation Y and single draw of W, psi | |
| from the posterior distribution. | |
| ''' | |
| k, d = W.shape[-2:] | |
| _, n = Y.shape |
This file contains hidden or 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) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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], |