/// <summary> /// A helper function for evidence messages when the output of the factor is observed. /// </summary> /// <param name="str">The observed value of <c>str</c>.</param> /// <param name="format">The message from <c>format</c>.</param> /// <param name="args">The message from <c>args</c>.</param> /// <param name="expectedLogEvidence"> /// The expected log-evidence if the format string is required to contain placeholders for all arguments. /// </param> /// <param name="expectedLogEvidenceWithMissingPlaceholders"> /// The expected log-evidence if the format string may not contain placeholders for some arguments. /// </param> private static void TestEvidence( string str, StringDistribution format, StringDistribution[] args, double expectedLogEvidence, double expectedLogEvidenceWithMissingPlaceholders) { const double LogEvidenceEps = 1e-6; string[] argNames = GetDefaultArgumentNames(args.Length); Assert.Equal( expectedLogEvidence, StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.LogEvidenceRatio(str, format, args), LogEvidenceEps); Assert.Equal( expectedLogEvidence, StringFormatOp_RequireEveryPlaceholder.LogEvidenceRatio(str, format, args, argNames), LogEvidenceEps); Assert.Equal( expectedLogEvidenceWithMissingPlaceholders, StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.LogEvidenceRatio(str, format, args), LogEvidenceEps); Assert.Equal( expectedLogEvidenceWithMissingPlaceholders, StringFormatOp_AllowMissingPlaceholders.LogEvidenceRatio(str, format, args, argNames), LogEvidenceEps); }
/// <summary> /// A helper function for evidence messages when the output of the factor is not observed. /// </summary> /// <param name="str">The message to <c>str</c>.</param>. private static void TestEvidence(StringDistribution str) { Assert.Equal(0, StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.LogEvidenceRatio(str)); Assert.Equal(0, StringFormatOp_RequireEveryPlaceholder.LogEvidenceRatio(str)); Assert.Equal(0, StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.LogEvidenceRatio(str)); Assert.Equal(0, StringFormatOp_AllowMissingPlaceholders.LogEvidenceRatio(str)); }