当前位置: 首页>>代码示例>>C#>>正文


C# Gamma.GetLogAverageOf方法代码示例

本文整理汇总了C#中Gamma.GetLogAverageOf方法的典型用法代码示例。如果您正苦于以下问题:C# Gamma.GetLogAverageOf方法的具体用法?C# Gamma.GetLogAverageOf怎么用?C# Gamma.GetLogAverageOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gamma的用法示例。


在下文中一共展示了Gamma.GetLogAverageOf方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="sample">Constant value for 'y'.</param>
		/// <param name="shape">Constant value for 'shape'.</param>
		/// <param name="rate">Incoming message from 'rate'.</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_(rate) p(rate) factor(y,shape,rate))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(double sample, double shape, Gamma rate)
		{
			// f(y,a,b) = y^(a-1) b^a/Gamma(a) exp(-by) = y^(-2) Gamma(a+1)/Gamma(a) Ga(b; a+1, y)
			Gamma to_rate = RateAverageConditional(sample, shape);
			return rate.GetLogAverageOf(to_rate) - 2*Math.Log(sample) + Math.Log(shape);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:16,代码来源:GammaFromShapeAndRate.cs

示例2: LogEvidenceRatio

		public static double LogEvidenceRatio([SkipIfUniform] Gamma sample, double shape, [SkipIfUniform] Gamma rate, Gamma to_sample)
		{
			return LogAverageFactor(sample, shape, rate) - to_sample.GetLogAverageOf(sample);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:4,代码来源:GammaFromShapeAndRate.cs

示例3: LogEvidenceRatio

		public static double LogEvidenceRatio([SkipIfUniform] Gamma exp, [Proper] Gaussian d, Gaussian to_d, Gamma to_exp)
		{
			return LogAverageFactor(exp, d, to_d) - to_exp.GetLogAverageOf(exp);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:4,代码来源:Exp.cs

示例4: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="exp">Incoming message from 'exp'.</param>
		/// <param name="d">Incoming message from 'd'.</param>
		/// <param name="to_d">Previous outgoing message to 'd'.</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_(exp,d) p(exp,d) factor(exp,d))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(Gamma exp, Gaussian d, Gaussian to_d)
		{
			if (d.IsPointMass) return LogAverageFactor(exp, d.Point);
			if (d.IsUniform()) return exp.GetLogAverageOf(new Gamma(0, 0));
			if (exp.IsPointMass) return LogAverageFactor(exp.Point, d);
			if (exp.IsUniform()) return 0.0;
			double[] nodes = new double[QuadratureNodeCount];
			double[] weights = new double[QuadratureNodeCount];
			double mD, vD;
			Gaussian dMarginal = d * to_d;
			dMarginal.GetMeanAndVariance(out mD, out vD);
			Quadrature.GaussianNodesAndWeights(mD, vD, nodes, weights);
			if (!to_d.IsUniform()) {
				// modify the weights to include q(y_k)/N(y_k;m,v)
				for (int i = 0; i < weights.Length; i++) {
					weights[i] *= Math.Exp(d.GetLogProb(nodes[i]) - Gaussian.GetLogProb(nodes[i], mD, vD));
				}
			}
			double Z = 0;
			for (int i = 0; i < weights.Length; i++) {
				double y = nodes[i];
				double f = weights[i] * Math.Exp((exp.Shape - 1) * y - exp.Rate * Math.Exp(y));
				Z += f;
			}
			return Math.Log(Z) - exp.GetLogNormalizer();
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:36,代码来源:Exp.cs


注:本文中的Gamma.GetLogAverageOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。