本文整理汇总了C#中VectorGaussian.SetMeanAndVariance方法的典型用法代码示例。如果您正苦于以下问题:C# VectorGaussian.SetMeanAndVariance方法的具体用法?C# VectorGaussian.SetMeanAndVariance怎么用?C# VectorGaussian.SetMeanAndVariance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VectorGaussian
的用法示例。
在下文中一共展示了VectorGaussian.SetMeanAndVariance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RotateAverageLogarithm
public static VectorGaussian RotateAverageLogarithm([SkipIfUniform] Gaussian x, [SkipIfUniform] Gaussian y, [Proper] WrappedGaussian angle, VectorGaussian result)
{
// for x ~ N(m,v):
// E[cos(x)] = cos(m)*exp(-v/2)
// E[sin(x)] = sin(m)*exp(-v/2)
if (angle.Period != 2*Math.PI) throw new ArgumentException("angle.Period ("+angle.Period+") != 2*PI ("+2*Math.PI+")");
double angleMean, angleVar;
angle.Gaussian.GetMeanAndVariance(out angleMean, out angleVar);
double expHalfVar = Math.Exp(-0.5*angleVar);
double mCos = Math.Cos(angleMean)*expHalfVar;
double mSin = Math.Sin(angleMean)*expHalfVar;
double mCos2 = mCos*mCos;
double mSin2 = mSin*mSin;
// E[cos(x)^2] = 0.5 E[1+cos(2x)] = 0.5 (1 + cos(2m) exp(-2v))
// E[sin(x)^2] = E[1 - cos(x)^2] = 0.5 (1 - cos(2m) exp(-2v))
double expVar = expHalfVar*expHalfVar;
// cos2m = cos(2m)*exp(-v)
double cos2m = 2*mCos2 - expVar;
double mCosSqr = 0.5*(1 + cos2m*expVar);
double mSinSqr = 1 - mCosSqr;
double mSinCos = mSin*mCos*expVar;
if (result.Dimension != 2) throw new ArgumentException("result.Dimension ("+result.Dimension+") != 2");
double mx, vx, my, vy;
x.GetMeanAndVariance(out mx, out vx);
y.GetMeanAndVariance(out my, out vy);
Vector mean = Vector.Zero(2);
mean[0] = mCos*mx - mSin*my;
mean[1] = mSin*mx + mCos*my;
double mx2 = mx*mx + vx;
double my2 = my*my + vy;
double mxy = mx*my;
PositiveDefiniteMatrix variance = new PositiveDefiniteMatrix(2, 2);
variance[0, 0] = mx2*mCosSqr - 2*mxy*mSinCos + my2*mSinSqr - mean[0]*mean[0];
variance[0, 1] = (mx2 - my2)*mSinCos + mxy*(mCosSqr - mSinSqr) - mean[0]*mean[1];
variance[1, 0] = variance[0, 1];
variance[1, 1] = mx2*mSinSqr + 2*mxy*mSinCos + my2*mCosSqr - mean[1]*mean[1];
result.SetMeanAndVariance(mean, variance);
return result;
}
示例2: ProductAverageConditional
/// <summary>
/// EP message to 'product'
/// </summary>
/// <param name="A">Constant value for 'a'.</param>
/// <param name="BMean">Buffer 'BMean'.</param>
/// <param name="BVariance">Buffer 'BVariance'.</param>
/// <param name="result">Modified to contain the outgoing message</param>
/// <returns><paramref name="result"/></returns>
/// <remarks><para>
/// The outgoing message is the factor viewed as a function of 'product' conditioned on the given values.
/// </para></remarks>
public static VectorGaussian ProductAverageConditional(Matrix A, [Fresh] Vector BMean, [Fresh] PositiveDefiniteMatrix BVariance, VectorGaussian result)
{
// P.mean = A*B.mean
// P.var = A*B.var*A'
// if A is invertible, then
// P.prec = inv(A)'*inv(B.var)*inv(A)
// P.precTimesMean = inv(A)'*B.precTimesMean
Vector rmean = A * BMean;
PositiveDefiniteMatrix rvariance = new PositiveDefiniteMatrix(result.Dimension, result.Dimension);
Matrix temp = (A*BVariance).Transpose();
rvariance.SetToProduct(A, temp);
result.SetMeanAndVariance(rmean, rvariance);
return result;
}
示例3: SubvectorAverageConditional
/// <summary>
/// EP message to 'subvector'
/// </summary>
/// <param name="SourceMean">Buffer 'SourceMean'.</param>
/// <param name="SourceVariance">Buffer 'SourceVariance'.</param>
/// <param name="startIndex">Constant value for 'startIndex'.</param>
/// <param name="result">Modified to contain the outgoing message</param>
/// <returns><paramref name="result"/></returns>
/// <remarks><para>
/// The outgoing message is the factor viewed as a function of 'subvector' conditioned on the given values.
/// </para></remarks>
public static VectorGaussian SubvectorAverageConditional([Fresh] Vector SourceMean, [Fresh] PositiveDefiniteMatrix SourceVariance, int startIndex, VectorGaussian result)
{
PositiveDefiniteMatrix subVariance = new PositiveDefiniteMatrix(result.Dimension, result.Dimension);
subVariance.SetToSubmatrix(SourceVariance, startIndex, startIndex);
Vector subMean = Vector.Zero(result.Dimension);
subMean.SetToSubvector(SourceMean, startIndex);
result.SetMeanAndVariance(subMean, subVariance);
return result;
}