Save the date! Google I/O returns May 18-20 Register now


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.


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.