Hi, I want to identify which chain is being used each time the simulator is run in Approximate Bayesian Computation (using sample_smc). I need this functionality because I want to use an external software to do the calculations. Does anyone know how to do that?
Simplifying a lot, here is what the script would look like:
def simulator(xs1, xs2, xs3, xs4, xs5): xs = [xs1, xs2, xs3, xs4, xs5] #searched model parameters chain_number = ? # identify chain number os.system("mkdir -p chain_"+chain_number) #create a folder with chain number appended generate_input(chain_number, xs) #generate input for the external software os.system("ansys chain_"+chain_number+"/input.inp") #run the input using external software result = read_result(chain_number) # read the result os.system("rm -rf chain_"+chain_number) #remove the folder with input file return result bay_scale_model = pm.Model() with bay_scale_model: # Priors for simulator model parameters BoundedNormal = pm.Bound(pm.Normal, lower = 0.0, upper = 2.4) xs1 = BoundedNormal("xs1", mu=1, sd=0.227689) xs2 = BoundedNormal("xs2", mu=1, sd=0.257015) xs3 = BoundedNormal("xs3", mu=1, sd=0.309559) xs4 = BoundedNormal("xs4", mu=1, sd=0.340311) xs5 = BoundedNormal("xs5", mu=1, sd=0.340311) sim = pm.Simulator("sim", simulator, params=(xs1, xs2, xs3, xs4, xs5), sum_stat="sort", epsilon=0.003, observed=observed_data) trace, sim_data = pm.sample_smc(2000, kernel="ABC", n_steps=20, parallel=True, save_sim_data=True, cores = 4, chains = 4, threshold=0.5) idata = az.from_pymc3(trace, posterior_predictive=sim_data)
So I need to know how to find chain_number.