Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with pm.Model() as m1:
- b_spe = pm.Normal('b_spe', 0, 5)
- b_noi = pm.Normal('b_noi', 0, 5)
- b_sn = pm.Normal('b_sn', 0, 5)
- sigma_sub = pm.HalfCauchy('sigma_sub', 1)
- sigma_run = pm.HalfCauchy('sigma_run', 1)
- a = pm.Normal('a', 0, 5)
- a_sub = pm.Normal('a_sub', 0, sigma_sub, shape=len(d['sub'].unique()))
- a_run = pm.Normal('a_run', 0, sigma_run, shape=len(d['run'].unique()))
- p = pm.invlogit(a + a_sub[d["sub"].values] + a_run[d["run"].values] + b_spe*d.speech
- + b_noi * d.noise + b_sn * d.speech * d.noise)
- hits = pm.Binomial('hits', p=p, n=d.total, observed=d.hit)
- trace_m1 = pm.sample(5000, tune=5000, njobs=4, target_accept=.99)
- with pm.Model() as m2:
- sd_dist = pm.HalfCauchy.dist(beta=2)
- pchol_sub = pm.LKJCholeskyCov('pchol_sub', eta=4, n=n_dim, sd_dist=sd_dist)
- chol = pm.expand_packed_triangular(n_dim, pchol_sub, lower=True)
- a = pm.Normal('a', 0, 1)
- sigma_sub = pm.HalfCauchy('sigma_sub', 1)
- a_sub = pm.Normal('a_sub', 0, sigma_sub, shape=n_subs)
- # includes beta for spe, noi, sn
- b_spe = pm.StudentT('b_spe', nu=3, mu=0, lam=1)
- b_noi = pm.StudentT('b_noi', nu=3, mu=0, lam=1)
- b_sn = pm.StudentT('b_sn', nu=3, mu=0, lam=1)
- # per subject
- b_s_sub = tt.dot(chol, pm.StudentT('b_s_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
- b_n_sub = tt.dot(chol, pm.StudentT('b_n_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
- b_sn_sub = tt.dot(chol, pm.StudentT('b_sn_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
- A = a + a_sub[d['sub'].values]
- B_s = b_spe + b_s_sub[0, d['sub'].values]
- B_n = b_noi + b_n_sub[0, d['sub'].values]
- B_sn = b_sn + b_sn_sub[0, d['sub'].values]
- sigma = pm.HalfCauchy('sigma', 2)
- lam = sigma ** -2
- nu = pm.Exponential('ν_minus_one', 1/29.) + 1
- mu = pm.Deterministic('mu', A + B_s * d.speech + B_n * d.noise + B_sn * d.speech * d.noise)
- psc = pm.StudentT('psc', nu=nu, mu=mu, lam=lam, observed=d.psc_c)
- trace_m2 = pm.sample(5000, tune=5000, njobs=4, target_accept=0.99)
Add Comment
Please, Sign In to add comment