Thanks for tuning in to Google I/O. View all sessions on demand

# oryx.core.ppl.intervene

Transforms a program into one where provided random variables are fixed.

### Used in the notebooks

Used in the tutorials

`intervene` is a probabilistic program transformation that fixes the values for certain random samples in an input program. A probabilistic program may sample intermediate latent random variables while computing its output. Observing those random variables converts them into deterministic constants that are just used in the forward computation.

Random variables that are intervened are no longer random variables. This means that if a variable `x` is intervened , it will no longer appear in the `joint_sample` of a program and its `log_prob` will no longer be computed as part of a program's `log_prob`.

## Examples:

### Simple usage:

``````def model(key):
return random_variable(random.normal, name='x')(key)
intervene(model, x=1.)(random.PRNGKey(0))  # => 1.
``````

### Multiple random variables:

``````def model(key):
k1, k2 = random.split(key)
z = random_variable(random.normal, name='z')(k1)
return z + random_variable(random.normal, name='x')(k2)
intervene(model, z=1., x=1.)(random.PRNGKey(0))  # => 2.
``````

`f` A probabilistic program.
`**observations` A dictionary mapping string names for random variables to values.

A probabilistic program that executes its input program with provided variables fixed to their values.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]