Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 /// <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));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// A helper function for testing messages to <c>format</c>.
 /// </summary>
 /// <param name="str">The message from <c>str</c>.</param>
 /// <param name="args">The message from <c>args</c>.</param>
 /// <param name="expectedFormatRequireEveryPlaceholder">
 /// The expected message to <c>format</c> if the format string is required to contain placeholders for all arguments.
 /// </param>
 /// <param name="expectedFormatAllowMissingPlaceholders">
 /// The expected message to <c>format</c> if the format string may not contain placeholders for some arguments.
 /// </param>
 private static void TestMessageToFormat(
     StringDistribution str,
     StringDistribution[] args,
     StringDistribution expectedFormatRequireEveryPlaceholder,
     StringDistribution expectedFormatAllowMissingPlaceholders)
 {
     string[] argNames = GetDefaultArgumentNames(args.Length);
     Assert.Equal(
         expectedFormatRequireEveryPlaceholder,
         StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.FormatAverageConditional(str, args));
     Assert.Equal(
         expectedFormatRequireEveryPlaceholder,
         StringFormatOp_RequireEveryPlaceholder.FormatAverageConditional(str, args, argNames));
     Assert.Equal(
         expectedFormatAllowMissingPlaceholders,
         StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.FormatAverageConditional(str, args));
     Assert.Equal(
         expectedFormatAllowMissingPlaceholders,
         StringFormatOp_AllowMissingPlaceholders.FormatAverageConditional(str, args, argNames));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// A helper function for testing messages to <c>args</c>.
        /// </summary>
        /// <param name="str">The message from <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="expectedArgsRequireEveryPlaceholder">
        /// The expected message to <c>args</c> if the format string is required to contain placeholders for all arguments.
        /// </param>
        /// <param name="expectedArgsAllowMissingPlaceholders">
        /// The expected message to <c>args</c> if the format string may not contain placeholders for some arguments.
        /// </param>
        private static void TestMessageToArgs(
            StringDistribution str,
            StringDistribution format,
            StringDistribution[] args,
            StringDistribution[] expectedArgsRequireEveryPlaceholder,
            StringDistribution[] expectedArgsAllowMissingPlaceholders)
        {
            string[] argNames = GetDefaultArgumentNames(args.Length);
            var      result   = new StringDistribution[args.Length];

            Assert.Equal(
                expectedArgsRequireEveryPlaceholder,
                StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.ArgsAverageConditional(str, format, args, result));
            Assert.Equal(
                expectedArgsRequireEveryPlaceholder,
                StringFormatOp_RequireEveryPlaceholder.ArgsAverageConditional(str, format, args, argNames, result));
            Assert.Equal(
                expectedArgsAllowMissingPlaceholders,
                StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.ArgsAverageConditional(str, format, args, result));
            var actualArgs = StringFormatOp_AllowMissingPlaceholders.ArgsAverageConditional(str, format, args, argNames, result);

            Assert.Equal(expectedArgsAllowMissingPlaceholders, actualArgs);
        }