# Partially constraining the Positive Definite Covariance Matrix • ### Question

• Hi,

I'm not sure whether to open a new thread or not for this topic. Anyway, ...

For a multivariate Guassian distribution, I would like to have diagonal or spherical covariance matrix (constrained Positive Definite Matrix). How can I specify this in Infer.NET? For full covariance, I'm aware that I have to specify:

Variable.VectorGaussianFromMeanAndPrecision(normal_distribution_on_the_mean, Wishart_distribution_on_precision)

But what about for diagonal or spherical case? For spherical case, since there is only one parameter for covariance matrix (identity matrix times constant: independent of the dimension) I'd like to do something like:

Variable.VectorGaussianFromMeanAndGamma(normal_distribution_on_the_mean, gamma_distribution_on_precision)

But I think that there is no such built-in conditional distribution.

Any help would be appreciated.
Monday, March 12, 2012 1:59 PM

### Answers

• The model you are talking about is equivalent to generating each element of a data vector separately, i.e.

data[n][k] = Variable.GaussianFromMeanAndPrecision(mean[z[n]][k], prec[z[n]][k])

To do this, define (data, mean, prec) as jagged arrays instead of arrays of vectors.

Tuesday, March 13, 2012 2:04 PM

### All replies

• The model you are talking about is equivalent to generating each element of a data vector separately, i.e.

data[n][k] = Variable.GaussianFromMeanAndPrecision(mean[z[n]][k], prec[z[n]][k])

To do this, define (data, mean, prec) as jagged arrays instead of arrays of vectors.

Tuesday, March 13, 2012 2:04 PM
• Hi Tom,

Thanks! I've just tried your suggestion and it works well. I was just wondering which is better (in terms of being more efficient, faster, etc for large datasets) when defining data, mean and prec (my dataset has fixed dimension for each data point):

rectangular array, i.e. VariableArray2D ()

or

jagged array, i.e. VariableArray<VariableArray<double>, double[][]>

Thanks again.

Wednesday, March 14, 2012 11:06 PM
• Jagged arrays will be the most efficient since we've put the most effort into optimizing them.  2D arrays are less common so we haven't optimized them as much.
Thursday, March 15, 2012 9:21 AM