New feature request: add support to dsl.py representing free and bound variables in a probabilistic expression
Opened this issue · 5 comments
Currently in Y0 we can associate values with variables and represent the probability of a set of variables in terms of other variables, but Y0 lacks a mechanism for representing
I see that, but I'm not convinced that the same can't be accomplished by having a pair of 1) the expression and 2) a dictionary mapping from the variable to its assignment
For example, you can have:
from y0.dsl import P, X, Variable
value = Variable('x')
expression = P(X)
assignments = {X: value}
If you had some more complicated expression that had multiple assignments, then maybe this is a different story, but I am not what that would look like besides
The issue is that counterfactual transportability requires knowledge of whether a variable is bound or free.
Examples of bound variables:
P(X == -x, Y == +y, Y @ -x == -y | Z == -z, W @ -x == -w)
Examples of free variables:
P(X, Y, Y @ -x | Z, W @ -x)
Here is a probabilistic expression with both free and bound variables:
P(X, Y== +y, Y @ -x | Z, W @ -x == -w)
The reason why this mixture can happen is that a variable that is free in an expression may be bound by an outer context such as a Sum
or Product
:
Sum[X](P(X, Y == -y))
It turns out that the counterfactual transportability algorithm can also have free or bound variables in an intervention, too!
So we can have:
Sum[X](P(Y @ X))
which is the same as:
P(Y @ +x) + P(Y @ -x)
Currently, interventions are always assumed to be bound variables, such that P(Y @ X)
is automatically converted to P(Y @ -X)
. However, the counterfactual transportability algorithm does generate expressions where an intervention can be a free variable. Furthermore, for any counterfactual variable, some of the interventions could be free, and others could be bound:
P(Y @ (X == -x, Z))
I don't quite understand what the meaning of the minus or plus sign is anymore with this proposal. This is syntactically valid, but I don't know what it should mean:
P(-Y @ x)
P(+Y @ x)
P(-Y @ -x)
P(+Y @ -x)
P(-Y @ +x)
P(+Y @ +x)
The current meaning of P(-Y @ x)
is that the value of the CounterfactualVariable
Y @ x
is -y
and the value of the Intervention
x
is -x
Note that P(-Y @ x)
has the same meaning as P(-Y @ -x)
because we have a restriction that if a Variable
is on the right-hand-side of @
then we coerce it into an Intervention
, which is not allowed to be a free variable (star
must be True
or False
).
Note also that a Variable
on the left-hand-side of @
can be a free variable (represented as having star=None
).
We currently cannot represent counterfactual variables that have Interventions as free variables, and while we can imagine scenarios where this will become a problem in the future, it is not a blocker for implementing any of the algorithms so far.
I think we can get 90% of what we want if we simply display dsl objects like P(-Y @ +x)
as