# Mixture of probabilities

**URL:** <https://discourse.pymc.io/t/mixture-of-probabilities/2113>\
**Category:** Questions\
**Created:** [October 28, 2018, 8:46pm UTC](https://discourse.pymc.io/t/mixture-of-probabilities/2113 "2018-10-28T20:46:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaddamanil16](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/gaddamanil16/32/927_2.png) [@gaddamanil16](https://discourse.pymc.io/u/gaddamanil16)\
**Post date:** [October 28, 2018, 8:46pm UTC](https://discourse.pymc.io/t/mixture-of-probabilities/2113/1 "2018-10-28T20:46:42Z")

</div>

Hi,

I am trying to formulate a mixture of Bernoulli for my task. I am unsure how pymc3 handles the p value for this.

My code snippet is:

```
with dir_model:

pi = pm.Dirichlet('pi', a = np.ones(K), shape = K)

dri = pm.Dirichlet('dri', a = np.ones((K, B)), shape = (K, B))

category_U = pm.Categorical('category_u', p = pi, shape = B)

vector_U = pm.Bernoulli('vec_u', p = dri[category_U], observed = Adj.toarray())

```

So here p value for `vector_U` will be of array shaped `B` for each observed value. So how will pymc3 handle this ? I think it will use it as mixture but I am not sure.

Help much appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 28, 2018, 9:20pm UTC](https://discourse.pymc.io/t/mixture-of-probabilities/2113/2 "2018-10-28T21:20:26Z")

</div>

> [@gaddamanil16](#):
>
> So here p value for `vector_U` will be of array shaped `B` for each observed value.

Correct. Since this is an observed variable, pymc3 will add the sum of logp to the model likelihood. The mixture concept is not particularly important here as pymc3 is not dealing with the parameterization directly (as it only care about the sum logp in this case).

---

<div class="post-metadata">

**Author:** ![gaddamanil16](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/gaddamanil16/32/927_2.png) [@gaddamanil16](https://discourse.pymc.io/u/gaddamanil16)\
**Post date:** [October 28, 2018, 11:48pm UTC](https://discourse.pymc.io/t/mixture-of-probabilities/2113/3 "2018-10-28T23:48:00Z")

</div>

> [@junpenglao](#):
>
> The mixture concept is not particularly important here as pymc3 is not dealing with the parameterization directly (as it only care about the sum logp in this case).

So can I consider it as a mixture of Bernoulli?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 30, 2018, 8:49am UTC](https://discourse.pymc.io/t/mixture-of-probabilities/2113/4 "2018-10-30T08:49:52Z")

</div>

Well it is equivalent to a mixture model and it is advice to rewrite it that way, but the way you wrote down above is not.
