# Gaussian Mixture (Migrated from community.research.microsoft.com) • ### Question

• Ali Yaghoubi posted on 03-05-2011 5:28 AM

Hi ,

I know that I am making a mistake that I think in each iteration means[z[n]] and precs[z[n]] just take means and precs that is only one of the two possible components of the mixture, because weights takes{1,1}.

Would you mind explaining more clear the events?

``` Variable<Vector> weights = Variable.Dirichlet(k, new double[] { 1, 1 }); ... VariableArray<int> z = Variable.Array<int>(n); ... using (Variable.ForEach(n)) {   z[n] = Variable.Discrete(weights);   using (Variable.Switch(z[n])) {     data[n] = Variable.VectorGaussianFromMeanAndPrecision(means[z[n]], precs[z[n]]);   } } Thanks ```

Friday, June 3, 2011 6:30 PM

• John Guiver replied on 03-07-2011 4:11 AM

Hi Ali

The first line creates a random variable  'weights' whose domain type is Vector. The prior for 'weights' is a Dirichlet distribution of dimension 2 whose pseudo-counts are 1 and 1. See http://en.wikipedia.org/wiki/Dirichlet_distribution and http://research.microsoft.com/en-us/um/cambridge/projects/infernet/codedoc/html/T_MicrosoftResearch_Infer_Distributions_Dirichlet.htm for more details.

'z' is a random variable array of type int. The two lines starting 'using Variable.ForEach[n]' say that each element of this random variable array is distributed according to a Discrete (or Categorical) distribution of dimension 2 whose probability vector is 'weights'. So z[n] is a random variable which can take on the values 0 or 1.The next line switches on the value of random variable.

John

Friday, June 3, 2011 6:30 PM