# Running inference (Migrated from community.research.microsoft.com)

• ### Question

• Ali Yaghoubi posted on 03-07-2011 1:27 PM

Hi Dear John,

In the first part of codes,maybe the data variablearray after being observed will be replaced with

individual Gaussian based random variables in the code after.

So, will the primary observed value be deleted while running the inference?

And what the roll of the data is here?

```VariableArray<double> data = Variable.Observed(new double[] { 11, 5, 8, 9 }); Range i = data.Range; data[i] = Variable.GaussianFromMeanAndPrecision(mean, precision).ForEach(i);```

...

```InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing()); // Retrieve the posterior distributions Gaussian marginalMean = engine.Infer<Gaussian>(mean); Gamma marginalPrecision = engine.Infer<Gamma>(precision);```

Thanks

Friday, June 3, 2011 6:30 PM

• John Guiver replied on 03-08-2011 8:33 AM

Hi Ali

The first line defines data as a random variable array which is observed to the specific values. The third line says how the data random variable array is related to the parameters mean and variance random variables - i.e. it defines the generative process for data. The observation on data acts a constraint on the model. It may be clearer and better practice to rewrite the first three lines as follows:

double[] dataVals = new double[] { 11, 5, 8, 9 };
Range i = new Range(dataVals.Length);
VariableArray<double> data = Variable.Array<double>(i);
data[i] =
Variable.GaussianFromMeanAndPrecision(mean, precision).ForEach(i);
data.ObservedValue = dataVals;

Note that if data is a scalar random variable rather than an array random variable you have to be a little bit more careful because '=' is not an overridable operator in .NET; so if you define a scalar random variable, observe it, and then redefine it as a function of some other random variable, the second definition overrides the first and Infer.NET cannot intercept this assignment. This is covered in the user guide: http://research.microsoft.com/infernet/docs/The%20importance%20of%20using%20SetTo.aspx.

Friday, June 3, 2011 6:30 PM