locked
Some questions about the SumOp and ExpOp RRS feed

  • Question

  • Following the great article "How to add a new factor and message operators", I tried to learn from the examples in the source code.

    In FastSumOp, 

            /// <summary>
            /// EP message to 'sum'
            /// </summary>
            /// <param name="array">Incoming message from 'array'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
            /// <returns>The outgoing EP message to the 'sum' argument</returns>
            /// <remarks><para>
            /// The outgoing message is a distribution matching the moments of 'sum' as the random arguments are varied.
            /// The formula is <c>proj[p(sum) sum_(array) p(array) factor(sum,array)]/p(sum)</c>.
            /// </para></remarks>
            /// <exception cref="ImproperMessageException"><paramref name="array"/> is not a proper distribution</exception>
            public static Gaussian SumAverageConditional([SkipIfAnyUniform] IList<Gaussian> array)
            {
                double mean = 0;
                double variance = 0;
                for (int i = 0; i < array.Count; i++) {
                    if (array[i].Precision == 0) return array[i];
                    double mean1;
                    double variance1;
                    array[i].GetMeanAndVarianceImproper(out mean1, out variance1);
                    mean = mean + mean1;
                    variance = variance + variance1;
                }
                return new Gaussian(mean, variance);
            }

    • What is the definition of Uniform in [SkipIfAnyUniform]? Is it equivalent to precision of Gaussian distribution is 0 in this case?  If so, why do we want to check  if (array[i].Precision == 0) return array[i]again?
    • The comments say Must be a proper distribution where does this code throw exception? From GetMeanAndVarianceImproper it seems Ok with improper ones?

    In ExpOp

        /// <summary>
            /// EP message to 'exp'
            /// </summary>
            /// <param name="exp">Incoming message from 'exp'.</param>
            /// <param name="d">Incoming message from 'd'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
            /// <param name="to_d">Previous outgoing message to 'd'.</param>
            /// <returns>The outgoing EP message to the 'exp' argument</returns>
            /// <remarks><para>
            /// The outgoing message is a distribution matching the moments of 'exp' as the random arguments are varied.
            /// The formula is <c>proj[p(exp) sum_(d) p(d) factor(exp,d)]/p(exp)</c>.
            /// </para></remarks>
            /// <exception cref="ImproperMessageException"><paramref name="d"/> is not a proper distribution</exception>
            public static Gamma ExpAverageConditional(Gamma exp, [Proper] Gaussian d, Gaussian to_d)
            ...

    • Are parameters d, to_d have to be named so becasue Math.Exp named its parameter "d"?
    • Where does the argument exp come from? i don't understand Incoming message from 'exp'. To my naive understanding, the factor should take d and produce exp.
    Friday, September 26, 2014 4:35 PM

Answers

  • 1. SkipIfAnyUniform is only a scheduling hint.  It does not guarantee that the operator will never be called with a uniform argument.

    2. The comments are out of date with the code.

    3. Yes.

    4. The argument exp is the message from the child variable into the factor.  EP requires this message for this factor.  Not all factors need to use this upward message, but Exp does.

    • Marked as answer by colinfang Friday, September 26, 2014 5:40 PM
    Friday, September 26, 2014 5:03 PM
    Owner