I’m trying to use a template model representation for a discrete-time dynamic bayesian network. The model is much more complicated, but here’s a simplified example:
Essentially, each time step has an identical structure, but then there’s some dependence at each time step on the previous one (but only on the previous one!).
My initial thoughts are to use a custom model, but I’m not sure how to repeat it, and in particular I’m not sure how to make it repeat and also be efficient. Any thoughts on implementing such a thing?
I’ve implemented the first step using a custom model, but unsure how to proceed.
class TemplateModel(pm.Model):
def __init__(self, mean=0, sd=1, name='', model=None):
super(TemplateModel, self).__init__(name, model)
v1 = pm.Normal('v1', mu=5, sd=sd)
v2 = pm.Normal('v2', mu=v1, sd=sd)
with pm.Model() as m:
m1 = TemplateModel(1,2,name='m1')
m2 = TemplateModel(2,3,name='m2')
m3 = pm.Deterministic('m3', 0.9*m1.v2+m2.v2)
trace = pm.sample(2000, njobs=4)
pm.traceplot(trace)