# How to infer components of mixture?

**URL:** <https://discourse.pymc.io/t/how-to-infer-components-of-mixture/5313>\
**Category:** Questions\
**Created:** [June 23, 2020, 7:54am UTC](https://discourse.pymc.io/t/how-to-infer-components-of-mixture/5313 "2020-06-23T07:54:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Jandsy](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@Jandsy](https://discourse.pymc.io/u/Jandsy)\
**Post date:** [June 26, 2020, 7:30am UTC](https://discourse.pymc.io/t/how-to-infer-components-of-mixture/5313/2 "2020-06-26T07:30:12Z")

</div>

Hello, I Have changed my code because it wasn’t really what I wanted to infer…  
Here is the new model, let’s imagine that I’m trying to compare mixture rank. To do that I’m using the following ressource [Order statistics in PyMC3](https://discourse.pymc.io/t/order-statistics-in-pymc3/617) . I got two components for each mixture in my case, and here is the new code that I’m using, K is the number of Mixture that I want to compare between each other:

> ```
> y_argsort = np.argsort(y, axis=0)
> component_1_dic = {}
> component_2_dic = {}
> mu_dic = {}
> weight_dic = {}
> with pm.Model() as mixture_model:
> for k in range(K):
> component_1_dic['component_1' + str(k)] = pm.Normal('component_1' + str(k), mu = 30, sigma = 8, shape=1)
> component_2_dic['component_2' + str(k)] = pm.Normal('component_2' + str(k), mu = 15, sigma = 6, shape=1)
> weight_dic['weight_' + str(k)] = pm.Bernoulli('weight_'+ str(k), p = 0.5, shape=1)
> theta_stacked = tt.stack([1-weight_dic['weight_' + str(k)], weight_dic['weight_' + str(k)]], axis=1)
> component_stacked = [component_1_dic['component_1' + str(k)].distribution, component_2_dic['component_2' + str(k)].distribution]
> mu_dic['mixture_' + str(k)] = pm.NormalMixture('mixture_' + str(k), w = theta_stacked , mu = tt.concatenate([component_1_dic['component_1' + str(k)], component_2_dic['component_2' + str(k)]]), sigma = pm.floatX([3, 4]), shape = 1)
> mu = tt.concatenate([mu_dic['mixture_' + str(0)]])
> for k in range(1, K):
> mu = tt.concatenate([mu, mu_dic['mixture_' + str(k)]])
> latent = pm.Normal('difference',
> mu=mu[y_argsort],
> sd=1, 
> transform=Ordered2D(), 
> shape=(K,J),
> testval=np.repeat(np.arange(K)[:,None], J, axis=1))
> trace = pm.sample(100000, tune=10000)
> 
> ```

My point is already the same, the components of my mixture doesn’t change a lot and python return each time : The number of effective samples is smaller than 10% for some parameters. I have tryied to rise the number of sample to the million (I have acces to a very good computer), and is already the same… Anyone could help me please ?

---

_[View the full topic](https://discourse.pymc.io/t/how-to-infer-components-of-mixture/5313)._
