# Likelihood of data belonging to mixture component

**URL:** <https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252>\
**Category:** v5\
**Tags:** modeling\
**Created:** [November 6, 2023, 11:28pm UTC](https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252 "2023-11-06T23:28:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tvwenger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tvwenger/32/7369_2.png) [@tvwenger](https://discourse.pymc.io/u/tvwenger)\
**Post date:** [November 6, 2023, 11:28pm UTC](https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252/1 "2023-11-06T23:28:16Z")

</div>

In v3, there was a discussion about using the component distributions of a mixture model to determine the likelihood that a given data point belongs to one of the components.

> [@Get probability of parameter given new data](https://discourse.pymc.io/t/get-probability-of-parameter-given-new-data/2511/4):
>
> In that case, you can evaluate the likelihood of y belonging to each component, and then normalized the likelihood, something like: ynew = np.asarray([.5]) complogp = y\_obs.distribution.\_comp\_logp(theano.shared(ynew)) f\_complogp = model\_mixed.model.fastfn(complogp) weight\_ynew = [] for ichain in range(trace\_mixed.nchains): for point\_idx in range(len(trace\_mixed)): point = trace\_mixed.\_straces[ichain].point(point\_idx) point.pop('sigma') point.pop('w') prob …

In v5, is there an easy way to access logp for the mixture components so we can do something similar with the new-and-improved Mixture class?

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [November 7, 2023, 6:09am UTC](https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252/2 "2023-11-07T06:09:04Z")

</div>

The last example in this blogpost uses sample\_posterior\_predictive to do exactly that: [Out of model predictions with PyMC - PyMC Labs](https://www.pymc-labs.com/blog-posts/out-of-model-predictions-with-pymc/)

---

<div class="post-metadata">

**Author:** ![iavicenna](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/iavicenna/32/7923_2.png) [@iavicenna](https://discourse.pymc.io/u/iavicenna)\
**Post date:** [November 7, 2023, 1:44pm UTC](https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252/3 "2023-11-07T13:44:16Z")

</div>

If you want the maths behind it, section 4 here explains it simply

> **[mixture\_models.pdf](https://www.cs.toronto.edu/~rgrosse/csc321/mixture_models.pdf)**
>
> 684.58 KB

Note compared to the link above, there is a further normalization factor (basically sum( w \* prob)) in the equation that guarantees probabilities sum to 1.

---

<div class="post-metadata">

**Author:** ![tvwenger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/tvwenger/32/7369_2.png) [@tvwenger](https://discourse.pymc.io/u/tvwenger)\
**Post date:** [November 7, 2023, 3:42pm UTC](https://discourse.pymc.io/t/likelihood-of-data-belonging-to-mixture-component/13252/4 "2023-11-07T15:42:05Z")

</div>

Many thanks!
