What is a good way to deal with defining multiple closely related PYMC models while avoiding duplicate code? For example , suppose I want to compare a model that uses Student_T versus Normal likelihood, and also I want to compare including certain features or not, etc.
My current approach is to use a function that creates the model, with a bunch of flags and enums… for example something like this but worse:
def build_model(data, mode = "condition", baseline = False, skew = False)
...
# set up the data (centering etc), define coordinates etc.
with pm.Model(coords = coords):
...
if not baseline:
# add priors for more features
if skew:
alpha = pm.Normal("alpha", mu = 0, sigma = 4)
pm.SkewNormal("y_obs", alpha = alpha, mu = mu, sigma = sigma, observed = y)
else:
pm.Normal("y_obs", mu = mu, sigma = sigma, observed = y)
return model
I must confess I have not fully searched the examples gallery, maybe there are some tips in there.