Calculating mean and variance of a data set<p>Hello,</p>
<p>This is a completely novice question, unfortunately I was unable to understand this from the Infer.NET tutorials.</p>
<p>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).</p>
<p>What I did was this:</p>
<pre class="prettyprint">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);
Console.ReadKey();</pre>
<br/>
<p>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.</p>
<p>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.</p>© 2009 Microsoft Corporation. All rights reserved.Mon, 28 Jan 2013 15:40:00 Zf587ab47-b9cf-4169-aff4-af4178b32873- https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#f587ab47-b9cf-4169-aff4-af4178b32873https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#f587ab47-b9cf-4169-aff4-af4178b32873robodashahttps://social.microsoft.com:443/profile/robodasha/?type=forumCalculating mean and variance of a data set<p>Hello,</p>
<p>This is a completely novice question, unfortunately I was unable to understand this from the Infer.NET tutorials.</p>
<p>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).</p>
<p>What I did was this:</p>
<pre class="prettyprint">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);
Console.ReadKey();</pre>
<br/>
<p>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.</p>
<p>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.</p>Wed, 16 Jan 2013 11:16:10 Z2013-01-16T11:16:10Z
- https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#1c48576a-3523-4674-ac4c-b3098a3832b7https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#1c48576a-3523-4674-ac4c-b3098a3832b7Yordan Zaykovhttps://social.microsoft.com:443/profile/yordan%20zaykov/?type=forumCalculating mean and variance of a data set<p>Hi,</p>
<p><span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10.909090995788574px; line-height:normal"><em>GaussianFromMeanAndVariance</em> is indeed experimental and shouldn't be used. You know that <em>variance = 1 / precision</em>,
so why don't you just learn the precision?</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10.909090995788574px; line-height:normal">Also, note that from a statistical point of view you set the prior of the Gaussian variance incorrectly - it should be an
<a href="http://en.wikipedia.org/wiki/Inverse-gamma_distribution">Inverse-gamma</a>. 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 (-:</span></p>
<p><span style="font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10.909090995788574px; line-height:normal">Thanks,<br/>
Yordan</span></p>Wed, 16 Jan 2013 17:48:21 Z2013-01-16T17:48:21Z
- https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#95e5f582-aee2-4542-bfc5-ad96781cfa02https://social.microsoft.com/Forums/en-US/f587ab47-b9cf-4169-aff4-af4178b32873/calculating-mean-and-variance-of-a-data-set?forum=infer.net#95e5f582-aee2-4542-bfc5-ad96781cfa02robodashahttps://social.microsoft.com:443/profile/robodasha/?type=forumCalculating mean and variance of a data setThank 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.Mon, 28 Jan 2013 15:43:44 Z2013-01-28T15:43:44Z