当前位置: 首页>>代码示例>>C#>>正文


C# PositiveDefiniteMatrix.Diagonal方法代码示例

本文整理汇总了C#中PositiveDefiniteMatrix.Diagonal方法的典型用法代码示例。如果您正苦于以下问题:C# PositiveDefiniteMatrix.Diagonal方法的具体用法?C# PositiveDefiniteMatrix.Diagonal怎么用?C# PositiveDefiniteMatrix.Diagonal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PositiveDefiniteMatrix的用法示例。


在下文中一共展示了PositiveDefiniteMatrix.Diagonal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SumAverageLogarithm

		/// <summary>
		/// VMP message to 'Sum'
		/// </summary>
		/// <param name="A">Incoming message from 'A'.</param>
		/// <param name="B">Incoming message from 'B'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <param name="MeanOfB">Buffer 'MeanOfB'.</param>
		/// <param name="CovarianceOfB">Buffer 'CovarianceOfB'.</param>
		/// <returns>The outgoing VMP message to the 'Sum' argument</returns>
		/// <remarks><para>
		/// The outgoing message is a distribution matching the moments of 'Sum' as the random arguments are varied.
		/// The formula is <c>proj[sum_(A,B) p(A,B) factor(Sum,A,B)]</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="B"/> is not a proper distribution</exception>
		public static Gaussian SumAverageLogarithm(DistributionStructArray<Bernoulli, bool> A, [SkipIfUniform] VectorGaussian B, Vector MeanOfB, PositiveDefiniteMatrix CovarianceOfB)
		{
			Gaussian result = new Gaussian();
			// p(x|a,b) = N(E[a]'*E[b], E[b]'*var(a)*E[b] + E[a]'*var(b)*E[a] + trace(var(a)*var(b)))
			Vector ma = Vector.Zero(A.Count);
			Vector va = Vector.Zero(A.Count);
			for (int i = 0; i < A.Count; i++) {
				ma[i] = A[i].GetMean();
				va[i] = A[i].GetVariance();
			}
			// Uses John Winn's rule for deterministic factors.
			// Strict variational inference would set the variance to 0.
			var MeanOfBSquared = Vector.Zero(MeanOfB.Count);
			MeanOfBSquared.SetToFunction(MeanOfB, x => x * x);
			result.SetMeanAndVariance(ma.Inner(MeanOfB), va.Inner(MeanOfBSquared) + CovarianceOfB.QuadraticForm(ma) + va.Inner(CovarianceOfB.Diagonal()));
			return result;
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:30,代码来源:SumWhere.cs

示例2: XAverageLogarithm

		/// <summary>
		/// VMP message to 'X'
		/// </summary>
		/// <param name="A">Incoming message from 'A'. Must be a proper distribution.  If all elements are uniform, the result will be uniform.</param>
		/// <param name="B">Incoming message from 'B'. Must be a proper distribution.  If all elements are uniform, the result will be uniform.</param>
		/// <param name="MeanOfB">Buffer 'MeanOfB'.</param>
		/// <param name="CovarianceOfB">Buffer 'CovarianceOfB'.</param>
		/// <param name="result">Modified to contain the outgoing message</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is a distribution matching the moments of 'X' as the random arguments are varied.
		/// The formula is <c>proj[sum_(A,B) p(A,B) factor(X,A,B)]</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="A"/> is not a proper distribution</exception>
		/// <exception cref="ImproperMessageException"><paramref name="B"/> is not a proper distribution</exception>
		public static Gaussian XAverageLogarithm([SkipIfAllUniform] GaussianArray A, [SkipIfAllUniform] VectorGaussian B, Vector MeanOfB, PositiveDefiniteMatrix CovarianceOfB)
		{
			int K = MeanOfB.Count;
			// p(x|a,b) = N(E[a]'*E[b], E[b]'*var(a)*E[b] + E[a]'*var(b)*E[a] + trace(var(a)*var(b)))
			var ma = Vector.Zero(K);
			var va = Vector.Zero(K);
			for (int k = 0; k < K; k++) {
				double m, v;
				A[k].GetMeanAndVariance(out m, out v);
				ma[k] = m;
				va[k] = v;
			}
			// Uses John Winn's rule for deterministic factors.
			// Strict variational inference would set the variance to 0.
			var mbj2 = Vector.Zero(K);
			mbj2.SetToFunction(MeanOfB, x => x * x);
			// slooow
			Gaussian result = new Gaussian();
			result.SetMeanAndVariance(ma.Inner(MeanOfB), va.Inner(mbj2) + CovarianceOfB.QuadraticForm(ma) + va.Inner(CovarianceOfB.Diagonal()));
			if (result.Precision < 0)
				throw new ApplicationException("improper message");

			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:39,代码来源:InnerProductPartialCovariance.cs


注:本文中的PositiveDefiniteMatrix.Diagonal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。