Changing the likelihood in example

Dear Edward users,

It is my intention to do inference in a mixture of different distributions, K Gaussians and one Uniform, in 3D.

So, first of all, I’ve tried to reproduce the examples which have some similarities with my problem. I’ve reproduced successfully the example within Github repository. But, I wonder why changing line 53

x = Normal(loc=tf.gather(mu, c), scale=tf.gather(sigma, c))


components = [
    MultivariateNormalDiag(tf.ones([N,1])*mu[k], tf.ones([N,1])*sigma[k])
    for k in range(K)]
x = Mixture(cat=c, components=components)

Which I think is more convenient to define my problem, Inference does not initialize. Please, any help will be welcome!

>>> inference.initialize()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/angel/src/edward/edward/inferences/", line 98, in initialize
    self.train = self.build_update()
  File "/home/angel/src/edward/edward/inferences/", line 127, in build_update
    x_znew = copy(x, dict_swap_new, scope=scope_new)
  File "/home/angel/src/edward/edward/util/", line 232, in copy
    new_rv = type(rv)(*args, **kwargs)
  File "/home/angel/src/edward/edward/models/", line 95, in __init__
    super(RandomVariable, self).__init__(*args, **kwargs)
  File "/home/angel/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/contrib/distributions/python/ops/", line 94, in __init__
TypeError: cat must be a Categorical distribution, but saw: Tensor("inference_139892168415760/old/Categorical_1/sample/Reshape_1:0", shape=(500,), dtype=int32)

Mixture represents a mixture distribution that collapses out the categorical, p(x) = \sum_{k=1}^K p(c = k) p(x | c = k). If you aim to use this collapsed version, then you don’t need to infer c in inference.

Specifically, using your proposed change along with

inference = ed.MetropolisHastings(
    latent_vars={pi: qpi, mu: qmu, sigma: qsigma},
    proposal_vars={pi: gpi, mu: gmu, sigma: gsigma},
    data={x: x_data})


It would be nice to raise a more informative error message for this.