本文整理汇总了C#中Gaussian.SetToSum方法的典型用法代码示例。如果您正苦于以下问题:C# Gaussian.SetToSum方法的具体用法?C# Gaussian.SetToSum怎么用?C# Gaussian.SetToSum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaussian
的用法示例。
在下文中一共展示了Gaussian.SetToSum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogOddsAverageConditional
/// <summary>
/// EP message to 'logOdds'.
/// </summary>
/// <param name="sample">Incoming message from sample.</param>
/// <param name="logOdds">Incoming message from 'logOdds'. Must be a proper distribution. If uniform, the result will be uniform.</param>
/// <returns>The outgoing EP message to the 'logOdds' argument.</returns>
/// <remarks><para>
/// The outgoing message is the moment matched Gaussian approximation to the factor.
/// </para></remarks>
public static Gaussian LogOddsAverageConditional(Bernoulli sample, [SkipIfUniform] Gaussian logOdds)
{
Gaussian toLogOddsT = LogOddsAverageConditional(true, logOdds);
double logWeightT = LogAverageFactor(true, logOdds) + sample.GetLogProbTrue();
Gaussian toLogOddsF = LogOddsAverageConditional(false, logOdds);
double logWeightF = LogAverageFactor(false, logOdds) + sample.GetLogProbFalse();
double maxWeight = Math.Max(logWeightT, logWeightF);
logWeightT -= maxWeight;
logWeightF -= maxWeight;
Gaussian result = new Gaussian();
result.SetToSum(Math.Exp(logWeightT), toLogOddsT * logOdds, Math.Exp(logWeightF), toLogOddsF * logOdds);
result /= logOdds;
return result;
}
示例2: ShapeAverageConditional
private static Gaussian ShapeAverageConditional(
Vector point, Bernoulli label, Gaussian shapeX, Gaussian shapeY, PositiveDefiniteMatrix shapeOrientation, bool resultForXCoord)
{
if (shapeX.IsPointMass && shapeY.IsPointMass)
{
double labelProbTrue = label.GetProbTrue();
double labelProbFalse = 1.0 - labelProbTrue;
double probDiff = labelProbTrue - labelProbFalse;
Vector shapeLocation = Vector.FromArray(shapeX.Point, shapeY.Point);
Vector diff = point - shapeLocation;
Vector orientationTimesDiff = shapeOrientation * diff;
Matrix orientationTimesDiffOuter = orientationTimesDiff.Outer(orientationTimesDiff);
double factorValue = Math.Exp(-0.5 * shapeOrientation.QuadraticForm(diff));
double funcValue = factorValue * probDiff + labelProbFalse;
Vector dFunc = probDiff * factorValue * orientationTimesDiff;
Vector dLogFunc = 1.0 / funcValue * dFunc;
Matrix ddLogFunc =
((orientationTimesDiffOuter + shapeOrientation) * factorValue * funcValue - orientationTimesDiffOuter * probDiff * factorValue * factorValue)
* (probDiff / (funcValue * funcValue));
double x = resultForXCoord ? shapeX.Point : shapeY.Point;
double d = resultForXCoord ? dLogFunc[0] : dLogFunc[1];
double dd = resultForXCoord ? ddLogFunc[0, 0] : ddLogFunc[1, 1];
return Gaussian.FromDerivatives(x, d, dd, forceProper: true);
}
else if (!shapeX.IsPointMass && !shapeY.IsPointMass)
{
VectorGaussian shapeLocationTimesFactor = ShapeLocationTimesFactor(point, shapeX, shapeY, shapeOrientation);
double labelProbFalse = label.GetProbFalse();
double shapeLocationWeight = labelProbFalse;
double shapeLocationTimesFactorWeight =
Math.Exp(shapeLocationTimesFactor.GetLogNormalizer() - shapeX.GetLogNormalizer() - shapeY.GetLogNormalizer() - 0.5 * shapeOrientation.QuadraticForm(point)) *
(1 - 2 * labelProbFalse);
var projectionOfSum = new Gaussian();
projectionOfSum.SetToSum(
shapeLocationWeight,
resultForXCoord ? shapeX : shapeY,
shapeLocationTimesFactorWeight,
shapeLocationTimesFactor.GetMarginal(resultForXCoord ? 0 : 1));
Gaussian result = new Gaussian();
result.SetToRatio(projectionOfSum, resultForXCoord ? shapeX : shapeY);
return result;
}
else
{
throw new NotSupportedException();
}
}