Model taking a long time to run

Hi I am new to pymc3 and I have a model that is taking a while to run. Any ideas on how to improve this? The model is below. Thanks

with pm.Model() as no_pooling_model_glm:

a = pm.Normal('a',mu = 0, sd = 1, shape = n_vendors)
b1 = pm.Normal('b1',mu = 0, sd = 1, shape = n_vendors) 
b2 = pm.Normal('b2', mu = 0, sd = 1, shape = n_vendors)

mu = pm.Deterministic('mu', a[vendor_id] + b1[vendor_id]*d['length_std'] +  b2[vendor_id]*d['length_std2'])

sigma = pm.Exponential('sigma', 1, shape = n_vendors)

time = pm.Normal('duration', mu = mu[vendor_id], sigma = sigma[vendor_id], observed = d.time_std)

diff_of_means = pm.Deterministic('diff_of_means', a[0] - a[1])


no_pooling_trace_glm = pm.sample(2000, tune = 1000, random_seed= seed)

It looks like mu is already matching the length of the observed, so you don’t need to index it again.

time = pm.Normal('duration', mu = mu, sigma = sigma[vendor_id], observed = d.time_std)

1 Like

Thanks! This was very helpful. Fixed the issue