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