Guest User

Untitled

a guest
Jan 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. with pm.Model() as m1:
  2. b_spe = pm.Normal('b_spe', 0, 5)
  3. b_noi = pm.Normal('b_noi', 0, 5)
  4. b_sn = pm.Normal('b_sn', 0, 5)
  5. sigma_sub = pm.HalfCauchy('sigma_sub', 1)
  6. sigma_run = pm.HalfCauchy('sigma_run', 1)
  7.  
  8. a = pm.Normal('a', 0, 5)
  9.  
  10. a_sub = pm.Normal('a_sub', 0, sigma_sub, shape=len(d['sub'].unique()))
  11. a_run = pm.Normal('a_run', 0, sigma_run, shape=len(d['run'].unique()))
  12.  
  13. p = pm.invlogit(a + a_sub[d["sub"].values] + a_run[d["run"].values] + b_spe*d.speech
  14. + b_noi * d.noise + b_sn * d.speech * d.noise)
  15. hits = pm.Binomial('hits', p=p, n=d.total, observed=d.hit)
  16.  
  17. trace_m1 = pm.sample(5000, tune=5000, njobs=4, target_accept=.99)
  18.  
  19. with pm.Model() as m2:
  20. sd_dist = pm.HalfCauchy.dist(beta=2)
  21. pchol_sub = pm.LKJCholeskyCov('pchol_sub', eta=4, n=n_dim, sd_dist=sd_dist)
  22. chol = pm.expand_packed_triangular(n_dim, pchol_sub, lower=True)
  23.  
  24. a = pm.Normal('a', 0, 1)
  25.  
  26. sigma_sub = pm.HalfCauchy('sigma_sub', 1)
  27. a_sub = pm.Normal('a_sub', 0, sigma_sub, shape=n_subs)
  28.  
  29. # includes beta for spe, noi, sn
  30. b_spe = pm.StudentT('b_spe', nu=3, mu=0, lam=1)
  31. b_noi = pm.StudentT('b_noi', nu=3, mu=0, lam=1)
  32. b_sn = pm.StudentT('b_sn', nu=3, mu=0, lam=1)
  33.  
  34. # per subject
  35. b_s_sub = tt.dot(chol, pm.StudentT('b_s_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
  36. b_n_sub = tt.dot(chol, pm.StudentT('b_n_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
  37. b_sn_sub = tt.dot(chol, pm.StudentT('b_sn_sub', nu=3, mu=0, lam=1, shape=(1, n_subs)))
  38.  
  39. A = a + a_sub[d['sub'].values]
  40. B_s = b_spe + b_s_sub[0, d['sub'].values]
  41. B_n = b_noi + b_n_sub[0, d['sub'].values]
  42. B_sn = b_sn + b_sn_sub[0, d['sub'].values]
  43.  
  44. sigma = pm.HalfCauchy('sigma', 2)
  45. lam = sigma ** -2
  46. nu = pm.Exponential('ν_minus_one', 1/29.) + 1
  47. mu = pm.Deterministic('mu', A + B_s * d.speech + B_n * d.noise + B_sn * d.speech * d.noise)
  48. psc = pm.StudentT('psc', nu=nu, mu=mu, lam=lam, observed=d.psc_c)
  49.  
  50. trace_m2 = pm.sample(5000, tune=5000, njobs=4, target_accept=0.99)
Add Comment
Please, Sign In to add comment