Hello all! I’m a PyMC novice, so sorry if this is the wrong place to ask this. Please feel free to direct me to the correct place.
I’m looking for some guidance in setting up a model-fitting procedure I’m working on. The model basically have 5 stochastic priors (U, R, D, F, f, and A), and two deterministic “time-series” variables (ui and Rn). ui and Rn depend on their initial conditions (U and R respectively). In addition, Rn[idx] depends on ui[idx]. I’ve been trying to make this work for a few days now, and I’m at a place where I need to ask for help.
I’ve tried a whole host of things that haven’t worked (i.e. days of error messages). I’ll spare you all that, and just show you what I have right now. I’m sure there’s a sensible way to accomplish this, and I’m hoping if I just share what I have, someone will be able to tell me a better way to handle it:
The function to calculate the updates to the ui and Rn variables is:
def calc_both(ui, R, U, f, dT, F, D):
ui_main_term = ui + f * (1 - ui) - U ui_exponential = np.exp(-dT/F) ui_full_term = U + (ui_main_term * ui_exponential) Rn_main_term = 1 - (R * (1 - ui)) Rn_exponential = np.exp(-(dT/D)) Rn_full_term = 1 - (Rn_main_term * Rn_exponential) return ui_full_term, Rn_full_term
And the model itself is specified as:
with pm.Model() as TM_model:
# Set constants dT = 0.1 stim_n = len(data) R = 1.0 # Set priors U = pm.Uniform('U', lower=0, upper=1) f = pm.Uniform('f', lower=0, upper=1) D = pm.Uniform('D', lower=0, upper=2) F = pm.Uniform('F', lower=0, upper=2) A = pm.Uniform('A', lower=20, upper=1000000) ui = U # Calculate dynamics result, updates = tn.scan(fn=calc_both, outputs_info=[ui, R], non_sequences=(U, f, dT, F, D), n_steps=stim_n) power = tn.function(inputs=[ui, R, U, f, dT, F, D], outputs=result, updates=updates, on_unused_input='warn') ui_Rn = power(ui, R, U, f, dT, F, D) ui = ui_Rn[0] Rn = ui_Rn[1] # Predict PSCs p_psc = A * ui * Rn # Define Likelihood p_data = pm.Normal('p_data', mu=p_psc, observed=data)
This particular example fails when setting up the Theano Scan function. I’ve tried implementing the loop in pure python, but that fails as well. Any advice would be appreciated!
TL;DR: I’m looking for a working way to specify two deterministic variables (ui, and Rn). They both depend on their initial condition (U and R respectively) and Rn depends on ui. Any help, guidance, or redirection is appreciated!