Interventional¶
Operations¶
- chirho.interventional.ops.intervene(obs, act: Intervention[T] | None = None, **kwargs)[source]¶
- chirho.interventional.ops.intervene(obs: Tensor, act: AtomicIntervention[T] | None = None, *, event_dim: int = 0, **kwargs) T
- chirho.interventional.ops.intervene(obs: bool, act: AtomicIntervention[T] | None = None, *, event_dim: int = 0, **kwargs) T
- chirho.interventional.ops.intervene(obs: float, act: AtomicIntervention[T] | None = None, *, event_dim: int = 0, **kwargs) T
- chirho.interventional.ops.intervene(obs: int, act: AtomicIntervention[T] | None = None, *, event_dim: int = 0, **kwargs) T
- chirho.interventional.ops.intervene(obs: pyro.distributions.Distribution, act: AtomicIntervention[pyro.distributions.Distribution] | None = None, **kwargs) pyro.distributions.Distribution
- chirho.interventional.ops.intervene(obs: dict[K, T], act: dict[K, AtomicIntervention[T]] | Callable[[dict[K, T]], dict[K, T]], **kwargs) dict[K, T]
- chirho.interventional.ops.intervene(obs: collections.abc.Callable, act: CompoundIntervention[T] | None = None, **call_kwargs) Callable[..., T]
Intervene on a value in a probabilistic program.
intervene()is primarily used internally inDoMessengerfor concisely and extensibly defining the semantics of interventions. This function is generically typed and extensible to new types viafunctools.singledispatch(). When its first argument is a function,intervene()now behaves like the current observational.do effect handler.- Parameters:
obs – a value in a probabilistic program.
act – an optional intervention.
Handlers¶
- class chirho.interventional.handlers.Interventions(actions: Mapping[Hashable, AtomicIntervention[T]])[source]¶
Intervene on values in a probabilistic program.
DoMessengeris an effect handler that intervenes at specified sample sites in a probabilistic program. This allows users to define programs without any interventional or causal semantics, and then to add those features later in the context of, for example,DoMessenger. This handler usesintervene()internally and supports the same types of interventions.
- chirho.interventional.handlers.do(fn: Callable, actions: Mapping[Hashable, AtomicIntervention[T]])[source]¶
Convenient wrapper of
InterventionsIntervene on values in a probabilistic program.
DoMessengeris an effect handler that intervenes at specified sample sites in a probabilistic program. This allows users to define programs without any interventional or causal semantics, and then to add those features later in the context of, for example,DoMessenger. This handler usesintervene()internally and supports the same types of interventions.