# Difference between Variable.Dirichlet(double[] u) and Variable.Dirichlet(Range valueRange, double[] u)? (Migrated from community.research.microsoft.com) • ### Question

• apple3101 posted on 07-24-2009 3:32 AM

hi everyone,

What is the difference between  Variable.Dirichlet(double[] u) and Variable.Dirichlet(Range valueRange, double[] u)?

I tried to use

Variable<Vector> pi = Variable.Dirichlet(new double[] { 0.1, 0.1 });
VariableArray<int> z = Variable.Array<int>(n);
VariableArray<Vector> x = Variable.Array<Vector>(n);

using(Variable.ForEach(n))
{
z[ n ] = Variable.Discrete(pi);
using(Variable.Switch(z[ n ]))
{
x[ n ] = Variable.VectorGaussianFromMeanAndPrecision(m[z[ n ]], lambda[z[ n ]]);
}
}

It won't compile.

Kevin

Friday, June 3, 2011 5:09 PM

• apple3101 replied on 07-24-2009 6:56 AM

so when z is used to index other variables, it should be provided with a valueRange or pi should be provided a range.

I found that it is OK to compile the code below.

Variable<Vector> pi = Variable.Dirichlet(new double[] { 1.0, 1.0 });

VariableArray<Vector> m = Variable.Array<Vector>(k);
VariableArray<PositiveDefiniteMatrix> lambda = Variable.Array<PositiveDefiniteMatrix>(k);

VariableArray<int> z = Variable.Array<int>(n);
VariableArray<Vector> x = Variable.Array<Vector>(n);

using(Variable.ForEach(n))
{
z = Variable.Discrete(pi).Attrib(new ValueRange(k));
using(Variable.Switch(z ))
{
x = Variable.VectorGaussianFromMeanAndPrecision(m[z ], lambda[z ]);
}

}

Friday, June 3, 2011 5:09 PM

### All replies

• minka replied on 07-24-2009 4:30 AM

The valueRange tells Infer.NET that the length of pi is the same as the length of that range.  In your case, you want to index the arrays m and lambda by z, and z comes from pi, so you should provide the range for (m,lambda) (not shown in your code) as the valueRange for pi.

Friday, June 3, 2011 5:09 PM
• apple3101 replied on 07-24-2009 6:56 AM

so when z is used to index other variables, it should be provided with a valueRange or pi should be provided a range.

I found that it is OK to compile the code below.

Variable<Vector> pi = Variable.Dirichlet(new double[] { 1.0, 1.0 });

VariableArray<Vector> m = Variable.Array<Vector>(k);
VariableArray<PositiveDefiniteMatrix> lambda = Variable.Array<PositiveDefiniteMatrix>(k);

VariableArray<int> z = Variable.Array<int>(n);
VariableArray<Vector> x = Variable.Array<Vector>(n);

using(Variable.ForEach(n))
{
z = Variable.Discrete(pi).Attrib(new ValueRange(k));
using(Variable.Switch(z ))
{
x = Variable.VectorGaussianFromMeanAndPrecision(m[z ], lambda[z ]);
}

}

Friday, June 3, 2011 5:09 PM