Weird shape behavior/error using a mixture

Hello,

I’m having super hard time to understand the shape behavior in a mixture model.
My model is a mixture with two components, c1 & c2 with shape = 24 (a day). Every thing works fine with a uniform distribution and an Poisson.
This is the code :

test_data = np.random.normal(size=24)
(min_,max_)=(test_data.min(), test_data.max())

with pm.Model() as model:
    day_mu = pm.Uniform('day_mu',lower=min_,upper=max_, shape=24) 
    day_sd = pm.HalfNormal('day_sd',sd=1, shape=24) # yes this RV is unused now, but will be used on the second example

    c1 = pm.Poisson.dist(mu=day_mu,shape=24) # !!
    c2 = pm.Uniform.dist(lower=min_, upper=max_, shape=24)
    
    w = pm.Dirichlet('w', a=np.array([1,1]), shape=(24,2))
    mix = pm.Mixture('mix', w=w, comp_dists=[c1, c2],observed = test_data) 
    trace = pm.sample() 

The problem arise when I replace the distribution type of the c1 component :

from :

c1 = pm.Poisson.dist(mu=day_mu,shape=24) # !!

to :

c1 = pm.Normal.dist(mu=day_mu, sd=day_sd, shape=24)

Note that shape is striclty the same, but when trying to execute I got this error message :

AttributeError: ‘list’ object has no attribute ‘mean’

During handling of the above exception, another exception occurred:

IndexError Traceback (most recent call last)
in ()
12
13 w = pm.Dirichlet(‘w’, a=np.array([1,1]), shape=(24,2))
—> 14 mix = pm.Mixture(‘mix’, w=w, comp_dists=[c1, c2],observed = test_data)
15 trace = pm.sample()

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in new(cls, name, *args, **kwargs)
39 raise TypeError(“observed needs to be data but got: {}”.format(type(data)))
40 total_size = kwargs.pop(‘total_size’, None)
—> 41 dist = cls.dist(*args, **kwargs)
42 return model.Var(name, dist, data, total_size)
43 else:

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/distribution.py in dist(cls, *args, **kwargs)
50 def dist(cls, *args, **kwargs):
51 dist = object.new(cls)
—> 52 dist.init(*args, **kwargs)
53 return dist
54

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/mixture.py in init(self, w, comp_dists, *args, **kwargs)
83
84 try:
—> 85 self.mean = (w * self._comp_means()).sum(axis=-1)
86
87 if ‘mean’ not in defaults:

~/anaconda3/lib/python3.6/site-packages/pymc3/distributions/mixture.py in _comp_means(self)
121 return tt.squeeze(tt.stack([comp_dist.mean
122 for comp_dist in self.comp_dists],
→ 123 axis=1))
124
125 def _comp_modes(self):

~/anaconda3/lib/python3.6/site-packages/theano/tensor/basic.py in stack(tensors, **kwargs)
4707 dtype = scal.upcast(
[i.dtype for i in tensors])
4708 return theano.tensor.opt.MakeVector(dtype)(*tensors)
→ 4709 return join(axis, *[shape_padaxis(t, axis) for t in tensors])
4710
4711

~/anaconda3/lib/python3.6/site-packages/theano/tensor/basic.py in (.0)
4707 dtype = scal.upcast(*[i.dtype for i in tensors])
4708 return theano.tensor.opt.MakeVector(dtype)(*tensors)
→ 4709 return join(axis, *[shape_padaxis(t, axis) for t in tensors])
4710
4711

~/anaconda3/lib/python3.6/site-packages/theano/tensor/basic.py in shape_padaxis(t, axis)
4599 if not -ndim <= axis < ndim:
4600 msg = ‘axis {0} is out of bounds [-{1}, {1})’.format(axis, ndim)
→ 4601 raise IndexError(msg)
4602 if axis < 0:
4603 axis += ndim

IndexError: axis 1 is out of bounds [-1, 1)

I don’t understand any of the two errors reported here.

And I don’t even understand why I do have an error…

Any help will be appreciated.