Distributional do-operator?

It’s already possible just not described. You can pass an arbitrary expression that depends on existing model variables:

with pm.Model() as m:
  x = pm.Normal("x")
  y = pm.Normal("y", x)

do_m = pm.do(m, {x: pm.math.switch(x > 0, x, 0})

You can also introduce new variables but they can’t be “named” model variables. You need to use dist.

with pm.Model() as m:
  x = pm.Normal("x")
  y = pm.Normal("y", x)

do_m = pm.do(m, {x: pm.Beta.dist()})

You can also add the variable to the model and then use it in the do intervention if for instance you want to sample it

with pm.Model() as m:
  x = pm.Normal("x")
  y = pm.Normal("y", x)

 
with m:
  new_x = pm.Beta("new_x")

do_m = pm.do(m, {x: new_x})
6 Likes