Infer.NET user guide : Sharing variables between models

Computing evidence for models with shared variables

Computing evidence in a shared variable model requires special treatment. In the non-shared variable case we just created a Variable<bool> evidence variable and wrapped the whole model in an IfBlock. The log evidence of the model was then given by the log odds of the evidence variable's marginal.

The following snippets show how to deal with evidence in the shared variable case, using the LDA shared variable example. You must first explicitly mark the evidence variable as such by setting the shared variable's IsEvidenceVariable property to true:

SharedVariable<bool> Evidence = SharedVariable<bool>.Random(new Bernoulli(0.5));
Evidence.IsEvidenceVariable =

Then wrap each model with an IfBlock conditioned on the model's copy of the evidence variable:

Model PhiDefModel = new Model(1);
<bool> EvidencePhiDef = Evidence.GetCopyFor(PhiDefModel);

evidencePhiDefBlock = Variable.If(EvidencePhiDef);

Model DocModel = new Model(numBatches);
Variable<bool> EvidenceDoc = Evidence.GetCopyFor(DocModel);
evidenceDocBlock = Variable.If(EvidenceDoc);

Finally, retrieve the log evidence by call the GetEvidenceForAll method, and passing in all models:

double logEvidence = Model.GetEvidenceForAll(PhiDefModel, DocModel);

©2009-2013 Microsoft Corporation. All rights reserved.  Terms of Use | Trademarks | Privacy Statement