Mixtures#
There are two ways to define mixtures in AePPL with Aesara constructs.
By creating an array of random variables and indexing it with a random variable:
import aesara.tensor as at
srng = at.random.RandomStream()
w_rv = srng.normal(-2, 1)
x_rv = srng.normal(0, 1)
y_rv = srng.normal(2, 1)
mix_rv = at.stack([w_rv, x_rv, y_rv])
p = at.vector('p')
i_rv = srng.categorical(p)
Z_rv = mix_rv[i_rv]
Using aesara.tensor.switch
:
import aesara.tensor as at
srng = at.random.RandomStream()
x_rv = srng.normal(0, 1)
y_rv = srng.normal(2, 1)
p = at.scalar('p')
i_rv = srng.bernoulli(p)
Z_rv = at.switch(i_rv, x_rv, y_rv)
Rewrites#
The following rewrites identify mixtures in Aesara graphs and replace them with MixtureRV
s, which are then used to compute the model’s log-density.
- aeppl.mixture.mixture_replace()#
A
NodeRewriter
constructed from a function.
- aeppl.mixture.switch_mixture_replace()#
A
NodeRewriter
constructed from a function.