Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and test a handler for intervening on random subsets of variables #247

Closed
eb8680 opened this issue Sep 4, 2023 · 0 comments · Fixed by #297
Closed

Add and test a handler for intervening on random subsets of variables #247

eb8680 opened this issue Sep 4, 2023 · 0 comments · Fixed by #297
Assignees
Labels
enhancement New feature or request module:explainable

Comments

@eb8680
Copy link
Contributor

eb8680 commented Sep 4, 2023

The design in #240 and previous iterations includes a number of new components on which the overall correctness of causation and explanation query implementations depends. To reduce the difficulty of reasoning about these implementations and make incremental progress toward landing causation and explanation queries in master, we should pull out these components and specify and test them in isolation.

One of these components is an effect handler that intervenes on randomly selected subsets of a set of possible variables. In the draft design in #240 this handler is called PartOfCause:

class PartOfCause(Protocol[P, S, T]):
    def __init__(self, actions: Mapping[str, Intervention[T]], *, bias: float, prefix: str): ...
    def __call__(self, fn: Callable[P, S]) -> Callable[P, S]: ...
    def __enter__(self): ...
    def __exit__(self, *args): ...

The implementation in #240 is quite compact thanks to #244's undo_split and the syntactic sugar of contextlib.contextmanager:

@contextlib.contextmanager
def PartOfCause(
    actions: Mapping[str, Intervention[T]],
    *,
    bias: float = 0.0,
    prefix: str = "__cause_split_",
):
    preemptions = {
        antecedent: undo_split(antecedents=[antecedent])
        for antecedent in actions.keys()
    }

    with do(actions=actions):
        with BiasedPreemptions(actions=preemptions, bias=bias, prefix=prefix):
            with pyro.poutine.trace() as logging_tr:
                yield logging_tr.trace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module:explainable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants