本文整理汇总了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);
}
}