# Shared Array of Wishart Distributions (Migrated from community.research.microsoft.com)

• ### Question

• omida posted on 05-18-2011 11:24 AM

Hi,

I want to share an array of Wishart priors between multiple models (for a GMM with lots of data). Similar to the shared variable LDA problems, I tried to define a prior over array of PositiveDefiniteMatrix like this:

Shared Variable LDA:

using DirichletArray=DistributionRefArray<Dirichlet, Vector>;

private static DirichletArray CreateUniformDirichletArray(
int length, int valueLength, Sparsity sparsity)
{
Dirichlet[] result = new Dirichlet[length];
for (int i=0; i < length; i++)
result[i] = Dirichlet.Uniform(valueLength, sparsity);
return (DirichletArray)Distribution<Vector>.Array<Dirichlet>(result);
}

Phi = SharedVariable<Vector>.Random(T, CreateUniformDirichletArray(numTopics, sizeVocab, phiSparsity)).Named("Phi");

Here is my attempt:

using WishartArray=DistributionRefArray<Wishart,PositiveDefiniteMatrix>;

private static WishartArray CreateUniformWishartArray(int length)
{
Wishart[] result = new Wishart[length];
for (int i=0; i < length; i++)
//result[i] = Variable.WishartFromShapeAndScale(100.0, PositiveDefiniteMatrix.IdentityScaledBy(2,0.1));
//result[i] = Dirichlet.Uniform(valueLength, sparsity);
result[i] = Wishart.Uniform(2);

return (WishartArray) Distribution<PositiveDefiniteMatrix>.Array<Wishart>(result);
}

Lambda_L = SharedVariable<PositiveDefiniteMatrix>.Random(rangeP,CreateUniformWishartArray(P)).Named("Lambda_L");

But I get this error in compile time:

/home/omida/Projects/VQ_SP_GMM_SC/VQ_SP_GMM_SC/VQ_SP_GMM_SC.cs(75,75): Error CS0309: The type `MicrosoftResearch.Infer.Distributions.DistributionRefArray<MicrosoftResearch.Infer.Distributions.Wishart,MicrosoftResearch.Infer.Maths.PositiveDefiniteMatrix>' must be convertible to `MicrosoftResearch.Infer.Distributions.IDistribution<DomainType[]>' in order to use it as parameter `DistributionArrayType' in the generic type or method `MicrosoftResearch.Infer.Models.SharedVariable<DomainType>.Random<DistributionArrayType>(MicrosoftResearch.Infer.Models.Range, DistributionArrayType)' (CS0309) (VQ_SP_GMM_SC)

(I am using Infer.Net with Mono on Ubuntu)

Any comments on this problem will be appreciated.

Cheers,

Omid

Friday, June 3, 2011 6:48 PM

• omida replied on 05-23-2011 3:00 AM

Hi John,

I can confirm that my first attempt(as written above) fails to compile under mono in Ubuntu(with the mentioned compile error) and compiles on native .Net on windows fine. The fix you suggested did not solve the problem under mono in Linux.

I am trying to write a mixture of multivariate T distributions for large data sizes(shared mean, precision and mixing components). I will try to find a workaround and if I could not, I will put the code that works under windows online so you could take a look at it(tomorrow).

Best,

Omid

Friday, June 3, 2011 6:49 PM

### All replies

• John Guiver replied on 05-19-2011 5:58 AM

Hi Omid

This seems to work fine on native .NET. I wonder if you need to be more explicit about the types.

Try being explicit about the Random method type argument:

Lambda_L = SharedVariable<PositiveDefiniteMatrix>.Random<WishartArray>(rangeP,CreateUniformWishartArray(P)).Named("Lambda_L");

If this doesn't work, let me know, and I'll think again.

John

Friday, June 3, 2011 6:49 PM
• omida replied on 05-19-2011 3:34 PM

Hi John,

As you pointed out, the same thing worked fine in Windows(Vista 64 + VS 2010)! I did not manage to get it working in Linux though.

I understand that your focus is not to get Infer.NET working on all environment, specially as you've mentioned that it has not been tested in Mono + Linux. However, it will be nice(and more useful for the community) to provide the same nice functionalities for other environments if possible.

Let me know if you thought of something to get it working in Linux.

Cheers,

Omid

Friday, June 3, 2011 6:49 PM
• John Guiver replied on 05-20-2011 11:29 AM

Hi Omid

I wasn't clear about your response. Can you confirm that (a) this works under Mono running on Windows, and (b) that the fix I suggested does not make a difference.

Thanks

John

Friday, June 3, 2011 6:49 PM
• omida replied on 05-23-2011 3:00 AM

Hi John,

I can confirm that my first attempt(as written above) fails to compile under mono in Ubuntu(with the mentioned compile error) and compiles on native .Net on windows fine. The fix you suggested did not solve the problem under mono in Linux.

I am trying to write a mixture of multivariate T distributions for large data sizes(shared mean, precision and mixing components). I will try to find a workaround and if I could not, I will put the code that works under windows online so you could take a look at it(tomorrow).

Best,

Omid

Friday, June 3, 2011 6:49 PM
• John Guiver replied on 05-24-2011 4:03 AM

Hi Omid

I can confirm that the following code does run under Mono, using the Windows version of Mono. So it looks like it might be an issue with the Linux version of Mono; unfortunately we are not really set up to investigate Linux-specific issues. Note that the code for distributions is shipped with the Infer.NET (in the Source folder, and also linked from the start menu), in particular DistributionRefArray is in Distribution.cs, and Wishart is in Wishart.cs. So I imagine you should be able to create a much simpler failure case for the Mono folks to look at.

John

Wishart[] wa = new Wishart[2];

for (int i = 0; i < 2; i++)

wa[i] = Wishart.FromShapeAndRate(2, 3.0, 4.0);

var wda = Distribution<PositiveDefiniteMatrix>.Array(wa);

Console.WriteLine(wda);

Friday, June 3, 2011 6:49 PM