本文整理汇总了C#中Gaussian.GetLogAverageOfPower方法的典型用法代码示例。如果您正苦于以下问题:C# Gaussian.GetLogAverageOfPower方法的具体用法?C# Gaussian.GetLogAverageOfPower怎么用?C# Gaussian.GetLogAverageOfPower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaussian
的用法示例。
在下文中一共展示了Gaussian.GetLogAverageOfPower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogAverageFactor
/// <summary>
/// Evidence message for EP
/// </summary>
/// <param name="logistic">Incoming message from 'logistic'.</param>
/// <param name="x">Incoming message from 'x'.</param>
/// <param name="falseMsg">Buffer 'falseMsg'.</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_(logistic,x) p(logistic,x) factor(logistic,x))</c>.
/// </para></remarks>
public static double LogAverageFactor(Beta logistic, Gaussian x, Gaussian falseMsg)
{
// return log(int_y int_x delta(y - Logistic(x)) Beta(y) Gaussian(x) dx dy)
double m,v;
x.GetMeanAndVariance(out m, out v);
if (logistic.TrueCount == 2 && logistic.FalseCount == 1) {
// shortcut for common case
return Math.Log(2*MMath.LogisticGaussian(m, v));
} else if (logistic.TrueCount == 1 && logistic.FalseCount == 2) {
return Math.Log(2*MMath.LogisticGaussian(-m, v));
} else {
// logistic(sigma(x)) N(x;m,v)
// = sigma(x)^(a-1) sigma(-x)^(b-1) N(x;m,v) gamma(a+b)/gamma(a)/gamma(b)
// = e^((a-1)x) sigma(-x)^(a+b-2) N(x;m,v)
// = sigma(-x)^(a+b-2) N(x;m+(a-1)v,v) exp((a-1)m + (a-1)^2 v/2)
// int_x logistic(sigma(x)) N(x;m,v) dx
// =approx (int_x sigma(-x)/falseMsg(x) falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v))^(a+b-2)
// * (int_x falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v))^(1 - (a+b-2))
// * exp((a-1)m + (a-1)^2 v/2) gamma(a+b)/gamma(a)/gamma(b)
// This formula comes from (66) in Minka (2005)
// Alternatively,
// =approx (int_x falseMsg(x)/sigma(-x) falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v))^(-(a+b-2))
// * (int_x falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v))^(1 + (a+b-2))
// * exp((a-1)m + (a-1)^2 v/2) gamma(a+b)/gamma(a)/gamma(b)
double tc1 = logistic.TrueCount-1;
double fc1 = logistic.FalseCount-1;
Gaussian prior = new Gaussian(m + tc1*v, v);
if (tc1+fc1 < 0) {
// numerator2 = int_x falseMsg(x)^(a+b-1) N(x;m+(a-1)v,v) dx
double numerator2 = prior.GetLogAverageOfPower(falseMsg, tc1+fc1+1);
Gaussian prior2 = prior*(falseMsg^(tc1+fc1+1));
double mp,vp;
prior2.GetMeanAndVariance(out mp, out vp);
// numerator = int_x (1+exp(x)) falseMsg(x)^(a+b-1) N(x;m+(a-1)v,v) dx / int_x falseMsg(x)^(a+b-1) N(x;m+(a-1)v,v) dx
double numerator = Math.Log(1 + Math.Exp(mp + 0.5*vp));
// denominator = int_x falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v) dx
double denominator = prior.GetLogAverageOfPower(falseMsg, tc1+fc1);
return -(tc1+fc1)*(numerator+numerator2-denominator) + denominator + (tc1*m + tc1*tc1*v*0.5) - logistic.GetLogNormalizer();
} else {
// numerator2 = int_x falseMsg(x)^(a+b-3) N(x;m+(a-1)v,v) dx
double numerator2 = prior.GetLogAverageOfPower(falseMsg, tc1+fc1-1);
Gaussian prior2 = prior*(falseMsg^(tc1+fc1-1));
double mp,vp;
prior2.GetMeanAndVariance(out mp, out vp);
// numerator = int_x sigma(-x) falseMsg(x)^(a+b-3) N(x;m+(a-1)v,v) dx / int_x falseMsg(x)^(a+b-3) N(x;m+(a-1)v,v) dx
double numerator = Math.Log(MMath.LogisticGaussian(-mp, vp));
// denominator = int_x falseMsg(x)^(a+b-2) N(x;m+(a-1)v,v) dx
double denominator = prior.GetLogAverageOfPower(falseMsg, tc1+fc1);
return (tc1+fc1)*(numerator+numerator2-denominator) + denominator + (tc1*m + tc1*tc1*v*0.5) - logistic.GetLogNormalizer();
}
}
}