Modeling Constrained Mixture Model

Hi All,

First post here and new to pyro so apologies if I am missing something obvious :slight_smile:

The examples section in the documentation has a really nicely worked out Gaussian mixture model example.

I was wondering, how would you extend that example so that certain observations are constrained to have the same value for the latent variable ? For instance I may want that x_i , where i mod 10 = k, for each k, should have the same value for the latent variable. In general, the indices for which the latent variables are constrained to be equal are also random, but the number of possible values for the latent variables (i.e. number of components) is fixed.

(This is not an idle curiosity question, but has come up in a problem I am trying to model).

Thanks in advance to anyone who responds - and great job building this package!

Hi @mhm,

I don’t fully understand your model, but one way to incorporate identity constraints is to first sample a set of independent random variables and then index into them. For example

def model(data, group):
    assert data.shape == group.shape
    with pyro.plate("independent", 10):
        locs = pyro.sample("locs", dist.Normal(0, 1))
    with pyro.plate("data", len(data)):
        pyro.sample("obs", dist.Normal(locs[group], 1.),

data = torch.randn(100)
groups = dist.Categorical(torch.ones(10)).sample(sample_shape=(100,))