# Calculating mean and variance of a data set • ### Question

• Hello,

This is a completely novice question, unfortunately I was unable to understand this from the Infer.NET tutorials.

I have a set of values (which in my case represent results of assignments which were students doing during some course). I want to represent these result with a Gaussian distribution. A tutorial "Learning a Gaussian" on Infer.NET website is showing how to do this, but I would like to have mean and variance priors (instead of mean and precision).

```InferenceEngine engine = new InferenceEngine();

Variable<double> meanPrior = Variable.GaussianFromMeanAndVariance(0, 100);
Variable<double> variancePrior = Variable.GammaFromShapeAndScale(2, 10);

VariableArray<double> x = Variable.Array<double>(student);
x[student] = Variable .GaussianFromMeanAndVariance(meanPrior, variancePrior).ForEach(student);
x.ObservedValue = averageStudentScores;

Gamma variancePosterior = engine.Infer<Gamma>(variancePrior);
Gaussian meanPosterior = engine.Infer<Gaussian>(meanPrior);

Console.WriteLine("mean=" + meanPosterior);
Console.WriteLine("variance=" + variancePosterior);

Unfortunately when I run the inference, I get three warnings (GaussianFromMeanAndVariance has band Experimental which is less than the recommended quality band) and the model doesn't run.

I was also trying just to calculate the mean and variance of the data manually and then create a Gaussian with these values, but that doesn't look as nice as using Infer.NET to do this.

Wednesday, January 16, 2013 11:16 AM

• Hi,

GaussianFromMeanAndVariance is indeed experimental and shouldn't be used. You know that variance = 1 / precision, so why don't you just learn the precision?

Also, note that from a statistical point of view you set the prior of the Gaussian variance incorrectly - it should be an Inverse-gamma. However, we don't have support for this distribution in our factors, because the ones that work with Gamma can be used instead. So your best bet at that point is really to learn the precision (-:

Thanks,
Yordan

• Marked as answer by Monday, January 28, 2013 3:40 PM
Wednesday, January 16, 2013 5:48 PM

### All replies

• Hi,

GaussianFromMeanAndVariance is indeed experimental and shouldn't be used. You know that variance = 1 / precision, so why don't you just learn the precision?

Also, note that from a statistical point of view you set the prior of the Gaussian variance incorrectly - it should be an Inverse-gamma. However, we don't have support for this distribution in our factors, because the ones that work with Gamma can be used instead. So your best bet at that point is really to learn the precision (-:

Thanks,
Yordan

• Marked as answer by Monday, January 28, 2013 3:40 PM
Wednesday, January 16, 2013 5:48 PM
• Thank you very much for your answer. I didn't understand from the error that actually the method itself is experimental. I used a precision prior instead in my model and it works as expected.
Monday, January 28, 2013 3:43 PM