2
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.

  • 1
    Generally, one should avoid for loops when working with Theano compute graphs because it results in the creation of tons of compute graph nodes. Instead, figure out how to express your operations with linear algebra and implement them with [the `theano.tensor` API](https://theano-pymc.readthedocs.io/en/latest/library/tensor/basic.html). – merv Apr 30 '21 at 14:15

0 Answers0