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


C# Dirichlet.Clone方法代码示例

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


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

示例1: MeanAverageLogarithm

		/// <summary>
		/// VMP message to 'mean'
		/// </summary>
		/// <param name="mean">Incoming message from 'mean'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <param name="totalCount">Incoming message from 'totalCount'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <param name="prob">Incoming message from 'prob'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <param name="to_mean">Previous outgoing message to 'mean'.</param>
		/// <returns>The outgoing VMP message to the 'mean' argument</returns>
		/// <remarks><para>
		/// The outgoing message is the exponential of the average log-factor value, where the average is over all arguments except 'mean'.
		/// The formula is <c>exp(sum_(totalCount,prob) p(totalCount,prob) log(factor(prob,mean,totalCount)))</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="mean"/> is not a proper distribution</exception>
		/// <exception cref="ImproperMessageException"><paramref name="totalCount"/> is not a proper distribution</exception>
		/// <exception cref="ImproperMessageException"><paramref name="prob"/> is not a proper distribution</exception>
		public static Dirichlet MeanAverageLogarithm([Proper] Dirichlet mean, [Proper] Gamma totalCount, [SkipIfUniform] Dirichlet prob, Dirichlet to_mean)
		{
			Vector gradS = CalculateGradientForMean(mean.PseudoCount, totalCount, prob.GetMeanLog());
			// Project onto Dirichlet, efficient matrix inversion (see TM's Dirichlet fitting paper)
			int K = mean.Dimension;
			Vector q = Vector.Zero(K);
			double gOverQ = 0, OneOverQ = 0;
			for (int k = 0; k < K; k++) {
				q[k] = MMath.Trigamma(mean.PseudoCount[k]);
				gOverQ += gradS[k] / q[k];
				OneOverQ += 1 / q[k];
			}
			double z = -MMath.Trigamma(mean.TotalCount);
			double b = gOverQ / (1 / z + OneOverQ);
			// Create new approximation and damp

			if (damping == 0.0) {
				to_mean.PseudoCount.SetToFunction(gradS, q, (x, y) => ((x - b) / y) + 1.0);
				return to_mean;
			} else {
				var old_msg = (Dirichlet)to_mean.Clone();
				to_mean.PseudoCount.SetToFunction(gradS, q, (x, y) => ((x - b) / y) + 1.0);
				return (to_mean ^ (1 - damping)) * (old_msg ^ damping);
			}
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:40,代码来源:DirichletOp.cs


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