How to insert for loop inside pm.Deterministic() to create an array in pymc3 model?

347 views Asked by At
with pm.Model() as model:
  w = pm.Uniform('w', 0, 1)
  c = pm.Uniform('c', 0, 5)
  b = 0.5
  s = pm.Deterministic('s', pm.math.exp(-c * (w * d1 + (1-w) * d2)))
  s_A = np.zeros((8)) 
  s_A = pm.Deterministic('s_A', for i in range(8) : s_A[i] = pm.math.sum(s[i][j] for j in (0,1,2,4)))
  s_B = np.zeros((8)) 
  s_B = pm.Deterministic('s_B', for i in range(8) : s_B[i] = pm.math.sum(s[i][j] for j in (3,5,6,7)))
  r = pm.Deterministic('r', b*s_A/(b*s_A + (1-b)*s_B))
  y = pm.Binomial('y', n= 320, p = r, observed = y_observed )
  trace = pm.sample(5000)


az.plot_posterior(trace, hdi_prob = 0.95)

I want to create a pymc3 model with the above parameters. d1 and d2 are both 8*8 matrices. The above code shows syntax error when I try to assign values to the s_A and s_B arrays. Can someone tell me what how to create variablles like s_A and s_B inside the pymc3 model.

0

There are 0 answers