Customising the algorithm initialisation

By default, Infer.NET initialises all messages to a uniform distribution.  It it sometimes necessary to override this behaviour, for example to break symmetries in the model or to initialise based on a custom preprocessing of the data.  Infer.NET supports overriding the initialisation of the algorithm by specifying an initial marginal for a variable or variables.

The syntax is:

Variable<double> x = Variable.GaussianFromMeanAndVariance(0, 1);
x.InitialiseTo(
Gaussian.FromMeanAndVariance(0, 10));

when the algorithm is initialised, the initial marginal for x will be set to a Gaussian with zero mean and a variance of 10.

Often you will need to initialise a variable array.  To do this, first build up a .NET array of the correct size. Then use the static Array method in the Distribution class to create the correct IDistribution type needed by InitialiseTo. For example,

Range r = new Range(10);
VariableArray<double> y = Variable.Array<double>(r);
Gaussian[] inity = new Gaussian[r.SizeAsInt];
for (int i = 0; i < inity.Count; i++)
    inity[i] =
Gaussian.FromMeanAndVariance(Rand.Normal(), 1);
y.InitialiseTo(Distribution<double>.Array(inity));

Here the initial marginals for the elements of y are set to be Gaussian with mean sampled from a standard Gaussian and with unit variance.  This kind of initialisation is useful for breaking symmetry.
 
Important note: Initialising a variable will often change the inference schedule used.  This is because the inference scheduler will use manually initialised messages in favour of automatically initialised ones, and so the order of operations may change.  The scheduler will also warn if the initialisation is unnecessary, for example, if the initial values supplied are never used.
©2009-2013 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement