#!/usr/bin/env python # coding: utf-8 # # Table of Contents #

# In[1]: import pymc3 as pm import numpy as np import theano.tensor as tt from theano import shared np.random.seed(42) # In[2]: y = shared(np.concatenate([np.random.poisson(5, size=10), np.random.poisson(9, size=10)])) x = shared(np.random.randn(20)) # In[3]: with pm.Model() as model: μ = pm.Normal('μ', 0, 1, shape=2) β = pm.Normal('β', 0, 1) lam = pm.Deterministic('lam', tt.exp(tt.outer(μ, β*x).T)) components = pm.Poisson.dist(mu=lam, shape=(20, 2)) w = pm.Dirichlet('w', a=np.array([1, 1])) # two mixture component weights. like = pm.Mixture('like', w=w, comp_dists=components, observed=y) # In[4]: with model: trace = pm.sample(1000) # In[5]: with model: pred = pm.sample_ppc(trace, samples=1000) # In[6]: pred['like'].shape