Customising the algorithm initialisationBy 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:
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. If you want each element to have the same initialiser, then this is easily done by syntax similar to the above:
More commonly, you want each element to have its own initialiser. In this case, you must first create a .NET array of the initialisers. From here there are two options. The first option is to create a VariableArray of distribution objects and observe it to be the .NET array. Then you apply InitialiseTo to each element of the array, as follows:
The second option is create a single distribution object holding the initialisers. Use the static Array method in the Distribution class to create the correct IDistribution type needed by InitialiseTo. For example,
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.