コード例 #1
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="AAverageConditional(Bernoulli, Poisson, int)"]/*'/>
        public static Poisson BAverageConditional([SkipIfUniform] Bernoulli isGreaterThan, int a, [Proper] Poisson b)
        {
            if (b.IsPointMass || !b.IsProper())
            {
                return(Poisson.Uniform());
            }
            double bMean = b.GetMean();
            double sum   = 0;
            double bsum  = 0;

            if (b.Precision == 1)
            {
                if (a > 0)
                {
                    sum  = MMath.GammaUpper(a, b.Rate);
                    bsum = (sum - Math.Exp(b.GetLogProb(a - 1))) * b.Rate;
                }
            }
            else
            {
                for (int i = 0; i < a; i++)
                {
                    double p = Math.Exp(b.GetLogProb(i));
                    sum  += p;
                    bsum += i * p;
                }
                if (sum > 1)
                {
                    sum = 1; // this can happen due to round-off errors
                }
                if (bsum > bMean)
                {
                    bsum = bMean;
                }
            }
            double  pT     = isGreaterThan.GetProbTrue();
            double  pF     = 1 - pT;
            double  Z      = pT * sum + pF * (1 - sum);
            double  bZ     = pT * bsum + pF * (bMean - bsum);
            Poisson result = new Poisson(bZ / Z);

            result.SetToRatio(result, b, false);
            return(result);
        }
コード例 #2
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="AAverageConditional(Bernoulli, Poisson, int)"]/*'/>
        public static Poisson AAverageConditional([SkipIfUniform] Bernoulli isGreaterThan, [Proper] Poisson a, int b)
        {
            if (a.IsPointMass || !a.IsProper())
            {
                return(Poisson.Uniform());
            }
            double aMean = a.GetMean();
            double sum   = 0;
            double asum  = 0;

            if (a.Precision == 1)
            {
                if (b >= 0)
                {
                    sum  = MMath.GammaUpper(b + 1, a.Rate);
                    asum = (sum - Math.Exp(a.GetLogProb(b))) * a.Rate;
                }
            }
            else
            {
                for (int i = 0; i <= b; i++)
                {
                    double p = Math.Exp(a.GetLogProb(i));
                    sum  += p;
                    asum += i * p;
                }
                if (sum > 1)
                {
                    sum = 1; // this can happen due to round-off errors
                }
                if (asum > aMean)
                {
                    asum = aMean;
                }
            }
            double  pT     = isGreaterThan.GetProbTrue();
            double  pF     = 1 - pT;
            double  Z      = pF * sum + pT * (1 - sum);
            double  aZ     = pF * asum + pT * (aMean - asum);
            Poisson result = new Poisson(aZ / Z);

            result.SetToRatio(result, a, false);
            return(result);
        }
コード例 #3
0
ファイル: PoissonOp.cs プロジェクト: xornand/Infer.Net
		/// <summary>
		/// Evidence message for VMP
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="mean">Constant value for 'mean'.</param>
		/// <returns>Average of the factor's log-value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>sum_(sample) p(sample) log(factor(sample,mean))</c>.
		/// Adding up these values across all factors and variables gives the log-evidence estimate for VMP.
		/// </para></remarks>
		public static double AverageLogFactor(Poisson sample, double mean)
		{
			return sample.GetMean() * mean - sample.GetMeanLogFactorial() - mean;
		}
コード例 #4
0
ファイル: PoissonOp.cs プロジェクト: xornand/Infer.Net
		/// <summary>
		/// Evidence message for VMP
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="mean">Incoming message from 'mean'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <returns>Average of the factor's log-value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>sum_(sample,mean) p(sample,mean) log(factor(sample,mean))</c>.
		/// Adding up these values across all factors and variables gives the log-evidence estimate for VMP.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="mean"/> is not a proper distribution</exception>
		public static double AverageLogFactor(Poisson sample, [Proper] Gamma mean)
		{
			return sample.GetMean() * mean.GetMeanLog() - sample.GetMeanLogFactorial() - mean.GetMean();
		}
コード例 #5
0
ファイル: PoissonOp.cs プロジェクト: mesgarpour/ERMER
 /// <summary>VMP message to <c>mean</c>.</summary>
 /// <param name="sample">Incoming message from <c>sample</c>. Must be a proper distribution. If uniform, the result will be uniform.</param>
 /// <returns>The outgoing VMP message to the <c>mean</c> argument.</returns>
 /// <remarks>
 ///   <para>The outgoing message is the exponential of the average log-factor value, where the average is over all arguments except <c>mean</c>. The formula is <c>exp(sum_(sample) p(sample) log(factor(sample,mean)))</c>.</para>
 /// </remarks>
 /// <exception cref="ImproperMessageException">
 ///   <paramref name="sample" /> is not a proper distribution.</exception>
 public static Gamma MeanAverageLogarithm([Proper] Poisson sample)
 {
     // p(mean) = exp(E[sample]*log(mean) - mean - E[log(sample!)])
     return(new Gamma(sample.GetMean() + 1, 1));
 }
コード例 #6
0
ファイル: PoissonOp.cs プロジェクト: mesgarpour/ERMER
 /// <summary>Evidence message for VMP.</summary>
 /// <param name="sample">Incoming message from <c>sample</c>.</param>
 /// <param name="mean">Constant value for <c>mean</c>.</param>
 /// <returns>Average of the factor's log-value across the given argument distributions.</returns>
 /// <remarks>
 ///   <para>The formula for the result is <c>sum_(sample) p(sample) log(factor(sample,mean))</c>. Adding up these values across all factors and variables gives the log-evidence estimate for VMP.</para>
 /// </remarks>
 public static double AverageLogFactor(Poisson sample, double mean)
 {
     return(sample.GetMean() * mean - sample.GetMeanLogFactorial() - mean);
 }
コード例 #7
0
ファイル: PoissonOp.cs プロジェクト: mesgarpour/ERMER
 /// <summary>Evidence message for VMP.</summary>
 /// <param name="sample">Incoming message from <c>sample</c>.</param>
 /// <param name="mean">Incoming message from <c>mean</c>. Must be a proper distribution. If uniform, the result will be uniform.</param>
 /// <returns>Average of the factor's log-value across the given argument distributions.</returns>
 /// <remarks>
 ///   <para>The formula for the result is <c>sum_(sample,mean) p(sample,mean) log(factor(sample,mean))</c>. Adding up these values across all factors and variables gives the log-evidence estimate for VMP.</para>
 /// </remarks>
 /// <exception cref="ImproperMessageException">
 ///   <paramref name="mean" /> is not a proper distribution.</exception>
 public static double AverageLogFactor(Poisson sample, [Proper] Gamma mean)
 {
     return(sample.GetMean() * mean.GetMeanLog() - sample.GetMeanLogFactorial() - mean.GetMean());
 }