Beispiel #1
0
        /// <summary>EP message to <c>str</c>.</summary>
        /// <param name="sub">Constant value for <c>sub</c>.</param>
        /// <param name="start">Constant value for <c>start</c>.</param>
        /// <param name="length">Constant value for <c>length</c>.</param>
        /// <returns>The outgoing EP message to the <c>str</c> argument.</returns>
        /// <remarks>
        ///   <para>The outgoing message is the factor viewed as a function of <c>str</c> conditioned on the given values.</para>
        /// </remarks>
        public static StringDistribution StrAverageConditional(string sub, int start, int length)
        {
            Argument.CheckIfNotNull(sub, "sub");
            Argument.CheckIfInRange(start >= 0, "start", "Start index must be non-negative.");
            Argument.CheckIfInRange(length >= 0, "length", "Length must be non-negative.");

            if (sub.Length != length)
            {
                return(StringDistribution.Zero());
            }

            StringDistribution result = StringDistribution.Any(minLength: start, maxLength: start);

            result.AppendInPlace(sub);
            result.AppendInPlace(StringDistribution.Any());
            return(result);
        }
        /// <summary>
        /// Creates a string distribution <c>P(s) = \prod_i P_i(s_i)^I[i != j]</c>,
        /// where <c>P_i(c)</c> is a given array of character distributions and <c>j</c> is a given position in the array.
        /// </summary>
        /// <param name="characters">The distributions over individual characters.</param>
        /// <param name="excludedPos">The character to skip.</param>
        /// <returns>The created distribution.</returns>
        private static StringDistribution GetCharWeighter(IList <DiscreteChar> characters, int excludedPos)
        {
            StringDistribution result = StringDistribution.Empty();

            for (int i = 0; i < characters.Count; ++i)
            {
                result.AppendInPlace(i == excludedPos ? DiscreteChar.Uniform() : characters[i]);
            }

            return(result);
        }
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="StringFromArrayOp"]/message_doc[@name="StrAverageConditional(IList{DiscreteChar})"]/*'/>
        public static StringDistribution StrAverageConditional(IList <DiscreteChar> characters)
        {
            StringDistribution result = StringDistribution.Empty();

            for (int i = 0; i < characters.Count; ++i)
            {
                result.AppendInPlace(characters[i]);
            }

            return(result);
        }