Automatic conditioning

Given a joint distribution p(dx,dy)=p(dx)p(dy∣x)p(\mathrm{d}x,\mathrm{d}y) = p(\mathrm{d}x) p(\mathrm{d}y\mid x), conditioning is the computation:

p(dx∣y)=p(y∣x)p(dx)p(y).p(\mathrm{d}x\mid y)=\frac{p(y\mid x)p(\mathrm{dx})}{p(y)}.

That is, we condition on the value of yy to obtain the conditional distribution of xx given yy. We may also refer to this as Bayesian updating, insofar as we interpret p(dx)p(\mathrm{d}x) as a prior distribution that we update to a posterior distribution p(dx∣y)p(\mathrm{d}x\mid y).

Automatic conditioning is supported for the same relationships as for automatic marginalization: standard conjugate forms, linear transformations, and sums and differences of discrete random variables.

Consider:

x ~ Gamma(2.0, 1.0);
y ~ Poisson(x);

Conditioning is triggered when y obtains a value. This can occur in several circumstances:

  • If, in the above code, y already has a value, or if the second line is replaced with #!birch y ~> Poisson(x);, then the conditioning is triggered immediately.
  • If, in the above code, y does not already have a value, but one is requested by replacing the second line with #!birch y <~ Poisson(x);, then the conditioning is triggered immediately.
  • If the above code remains the same, but y.value() is later used to obtain a value for y, then the conditioning is triggered at that time.

In all of these cases x remains marginalized out, but the distribution associated with it is updated to the conditional distribution of x given y. If x.value() is later used to obtain a value for x, it will be drawn from that conditional distribution. In this way random variables are simulated consistently from the joint distribution.

Conditioning can occur multiple times:

x ~ Gamma(2.0, 1.0);
y <~ Poisson(x);
z <~ Poisson(x);

Here, the distribution associated with x is updated twice, to the conditional distribution given both y and z.