 # Implement deterministic function and var

Greetings!

I am trying to implement a function of several random variables, then, use the function ‘sim’ to assign a Deterministic Variable ‘cumulative’. However, I get some problems as following:

1、when ‘O=o0’ in function ‘sim’, I get “setting an array element with a sequence”
2、what`s the appropriate way to get Deterministic function and vars in pymc3(just like the '@pymc.deterministic 'in pymc)

And my code is here.:

T = 20

def sim(lami=lami, lamd=lamd, pir=pir, e0 = e0, o0 = o0):

``````O = np.zeros(T)
Sd = np.zeros(T)
D = np.zeros(T)
cumulative_cases = np.zeros(T)
# initialize
O = o0
Sd = 1072
D = 23
cumulative_cases = 495

for j in range(1, T):
O[j] = O[j - 1] - lami * O[j - 1] - lamd * O[j - 1] - pir * O[j - 1]
Sd[j] = Sd[j - 1] + lamd*O[j - 1] - 1/14 * Sd[j - 1]
D[j] = D[j - 1] + pir * O[j - 1]
cumulative_cases[j] = cumulative_cases[j-1] + lami*O[j - 1]

return cumulative_cases, D
``````

with pm.Model() as model:

``````lami = pm.Uniform('lami', 0.1, 1)
lamd = pm.Uniform('lamd', 1e-9, 1)
pir = pm.Uniform('pir', 0.1, 1)
e0 = pm.Uniform('e0', 0, 100000)
o0 = pm.Uniform('o0', 0, 100000)

cumulative = pm.Deterministic('cumulative', sim(lami, lamd, pir, e0, o0))
``````

Any feedback is very welcomed! Thanks very much!