Example #1
0
 /// <summary>VMP message to <c>item</c>.</summary>
 /// <param name="array">Incoming message from <c>array</c>. Must be a proper distribution. If all elements are uniform, the result will be uniform.</param>
 /// <param name="index1">Constant value for <c>index1</c>.</param>
 /// <param name="index2">Constant value for <c>index2</c>.</param>
 /// <param name="result">Modified to contain the outgoing message.</param>
 /// <returns>
 ///   <paramref name="result" />
 /// </returns>
 /// <remarks>
 ///   <para>The outgoing message is a distribution matching the moments of <c>item</c> as the random arguments are varied. The formula is <c>proj[sum_(array) p(array) factor(item,array,index1,index2)]</c>.</para>
 /// </remarks>
 /// <exception cref="ImproperMessageException">
 ///   <paramref name="array" /> is not a proper distribution.</exception>
 /// <typeparam name="Distribution">The type of the distribution over an item.</typeparam>
 public static Distribution ItemAverageLogarithm <Distribution>(
     [SkipIfAllUniform] IArray2D <Distribution> array, int index1, int index2, Distribution result)
     where Distribution : SettableTo <Distribution>
 {
     result.SetTo(array[index1, index2]);
     return(result);
 }
Example #2
0
 /// <summary>
 /// Print the means of a 2-D array of Gaussians to the console
 /// </summary>
 /// <param name="matrix"></param>
 private static void printMatrixToConsole(IArray2D <Gaussian> matrix)
 {
     for (int i = 0; i < matrix.GetLength(0); i++)
     {
         for (int j = 0; j < matrix.GetLength(1); j++)
         {
             Console.Write("{0,5:0.00}\t", matrix[i, j].GetMean());
         }
         Console.WriteLine("");
     }
 }
Example #3
0
        /// <summary>
        /// Mean absolute row means
        /// </summary>
        /// <param name="matrix"></param>
        /// <returns></returns>
        private static double[] meanAbsoluteRowMeans(IArray2D <Gaussian> matrix)
        {
            double[] mam  = new double[matrix.GetLength(0)];
            double   mult = 1.0 / ((double)matrix.GetLength(1));

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                double sum = 0.0;
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    sum += System.Math.Abs(matrix[i, j].GetMean());
                }
                mam[i] = mult * sum;
            }
            return(mam);
        }
Example #4
0
 /// <summary>Evidence message for EP.</summary>
 /// <param name="item">Incoming message from <c>item</c>.</param>
 /// <param name="array">Incoming message from <c>array</c>.</param>
 /// <param name="index1">Constant value for <c>index1</c>.</param>
 /// <param name="index2">Constant value for <c>index2</c>.</param>
 /// <returns>Logarithm of the factor's contribution the EP model evidence.</returns>
 /// <remarks>
 ///   <para>The formula for the result is <c>log(sum_(item,array) p(item,array) factor(item,array,index1,index2) / sum_item p(item) messageTo(item))</c>. Adding up these values across all factors and variables gives the log-evidence estimate for EP.</para>
 /// </remarks>
 /// <typeparam name="Distribution">The type of the distribution over an item.</typeparam>
 public static double LogEvidenceRatio <Distribution>(T item, IArray2D <Distribution> array, int index1, int index2)
     where Distribution : CanGetLogProb <T>
 {
     return(LogAverageFactor(item, array, index1, index2));
 }
Example #5
0
 /// <summary>Evidence message for EP.</summary>
 /// <param name="item">Incoming message from <c>item</c>.</param>
 /// <param name="array">Incoming message from <c>array</c>.</param>
 /// <param name="index1">Constant value for <c>index1</c>.</param>
 /// <param name="index2">Constant value for <c>index2</c>.</param>
 /// <returns>Logarithm of the factor's average value across the given argument distributions.</returns>
 /// <remarks>
 ///   <para>The formula for the result is <c>log(sum_(item,array) p(item,array) factor(item,array,index1,index2))</c>.</para>
 /// </remarks>
 /// <typeparam name="Distribution">The type of the distribution over an item.</typeparam>
 public static double LogAverageFactor <Distribution>(T item, IArray2D <Distribution> array, int index1, int index2)
     where Distribution : CanGetLogProb <T>
 {
     return(array[index1, index2].GetLogProb(item));
 }
Example #6
0
 public Manhattan2DNode(short x, short y, IArray2D tab)
 {
     X   = x;
     Y   = y;
     Map = tab;
 }