Replies: 1 comment
-
To illustrate why this may be less than expected, consider the following interface which uses a single scalar placeholder value to infer an def missing(missval: float) -> ContextManager:
...
MISSVAL = 0.12345
x_obs[torch.isnan(x_obs)] = MISSVAL
conditioned_model = missing(missval=MISSVAL)(
pyro.condition(data={"x": x_obs})(
model))
# conditioned_model is equivalent to:
def model():
...
x = pyro.sample("x", ..., obs=x_obs, obs_mask=(x_obs == MISSVAL))
... Here is a sketch of an implementation of class missing(pyro.poutine.messenger.Messenger):
def __init__(self, missval: float):
self.missval = missval
super().__init__()
def _pyro_sample(self, msg):
if (
msg["is_observed"]
and msg["value"] is not None
and not pyro.poutine.util.site_is_subsample(msg)
and not site_is_deterministic(msg)
):
msg["stop"] = True
msg["done"] = True
with pyro.poutine.messenger.block_messengers(lambda m: m is self):
msg["value"] = pyro.sample(
msg["name"],
msg["fn"],
obs=msg["value"],
obs_mask=(msg["value"] != self.missval),
infer=msg["infer"].copy(),
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Many real-world causal inference tasks, such as the mediation analysis example #14, involve working with datasets that have randomly or systematically missing data.
Pyro is already well-equipped to support simultaneous inference and imputation thanks to the
obs_mask
keyword argument topyro.sample
. That includes systematic missingness of the form discussed by Pearl in Graphical Models for Inference with Missing Databecause the value of
obs_mask
can depend on random variables and other computations within a (causal) Pyro program.However,
obs_mask
cannot be read or modified by effect handlers or reparameterizers. IIRC this was a design choice made to ensure that imputation composed correctly with the rest of Pyro (closely related to the discussions in #30 and #82), but as a result it is currently somewhat difficult to separate the specification of a causal model, a set of observed values, and a pattern of missingness.The semantics of
obs_mask
is quite simple, so to get around this limitation we could do something like the following:obs_mask
handling that takes anobs_mask
value for a singlesample
site as inputreparam.Strategy
similar to the existing effect handlerpyro.poutine.mask
for higher-level specification of patterns of missingness across multiplesample
sitesSome design questions:
pyro.poutine.mask
andMultiWorldCounterfactual
? See Specify algebraic relationships between transformations #30Beta Was this translation helpful? Give feedback.
All reactions