I am trying to use the same pymc3 model to fit many (~100) set of data. Since I found no way to reuse the model, I create it new. This is the basic code:
for i in range(100):
Y = data[i]
mod = pm.Model()
with mod:
p = pm.Uniform('p',lower=0.1,upper=3 ,testval=2)
Y_obs = pm.Binomial('Y_obs',n=100,p=z,observed=Y)
err = 1
try:
trace = pm.sample(5000)
err = 0
result.append(trace)
del mod
if err == 0:
del trace
With this method the process becomes slower over time and my ram usage seams to increase until it seems full which most likely is the reason for the slow down.
Is there a better way to fit the same model to different sets of data?
It looks like most of the trouble with your code is python related -- you can reuse a model by returning it from a function:
Then you can iterate through your data
Diagnosing the memory issues would require knowing more about what the data looks like. You might try sampling everything at once -- something like
This should speed things up, but will not help much with memory.