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


C# Discrete.GetProbs方法代码示例

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


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

示例1: SelectorAverageConditional

		/// <summary>
		/// EP message to 'selector'.
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'selector'.
		/// The formula is <c>int f(selector,x) q(x) dx</c> where <c>x = (sample,probs)</c>.
		/// </para></remarks>
		public static Discrete SelectorAverageConditional(Discrete sample, Matrix probs, Discrete result)
		{
			Vector v = result.GetWorkspace();
			v.SetToProduct(probs, sample.GetProbs());
			result.SetProbs(v);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:18,代码来源:DiscreteFromDiscrete.cs

示例2: SampleAverageConditional

		/// <summary>
		/// EP message to 'sample'.
		/// </summary>
		/// <param name="selector">Incoming message from 'selector'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'sample'.
		/// The formula is <c>int f(sample,x) q(x) dx</c> where <c>x = (selector,probs)</c>.
		/// </para></remarks>
		public static Discrete SampleAverageConditional(Discrete selector, Matrix probs, Discrete result)
		{
			Vector v = result.GetWorkspace();
			v.SetToProduct(selector.GetProbs(), probs);
			result.SetProbs(v);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:18,代码来源:DiscreteFromDiscrete.cs

示例3: AAverageConditional

		/// <summary>
		/// EP message to 'a'.
		/// </summary>
		/// <param name="areEqual">Constant value for 'areEqual'.</param>
		/// <param name="B">Incoming message from 'b'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'a'.
		/// The formula is <c>int f(a,x) q(x) dx</c> where <c>x = (areEqual,b)</c>.
		/// </para></remarks>
		public static Discrete AAverageConditional(bool areEqual, Discrete B, Discrete result)
		{
			if (B.IsPointMass) return AAverageConditional(areEqual, B.Point, result);
			if (result == default(Discrete)) result = Distributions.Discrete.Uniform(B.Dimension, B.Sparsity);
			if (areEqual) result.SetTo(B);
			else {
				Vector probs = result.GetWorkspace();
				probs = B.GetProbs(probs);
				probs.SetToDifference(1.0, probs);
				result.SetProbs(probs);
			}
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:24,代码来源:AreEqual.cs

示例4: AAverageLogarithm

		/// <summary>
		/// VMP message to 'a'.
		/// </summary>
		/// <param name="areEqual">Incoming message from 'areEqual'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <param name="B">Incoming message from 'b'.</param>
		/// <param name="result">Modified to contain the outgoing message.</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the exponential of the average log-factor value, where the average is over all arguments except 'a'.
		/// Because the factor is deterministic, 'areEqual' is integrated out before taking the logarithm.
		/// The formula is <c>exp(sum_(b) p(b) log(sum_areEqual p(areEqual) factor(areEqual,a,b)))</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="areEqual"/> is not a proper distribution</exception>
		public static Discrete AAverageLogarithm([SkipIfUniform] Bernoulli areEqual, Discrete B, Discrete result)
		{
			if (areEqual.IsPointMass) return AAverageLogarithm(areEqual.Point, B, result);
			if (result == default(Discrete)) result = Discrete.Uniform(B.Dimension, B.Sparsity);
			// when AreEqual is marginalized, the factor is proportional to exp((A==B)*areEqual.LogOdds)
			Vector probs = result.GetWorkspace();
			probs = B.GetProbs(probs);
			probs.SetToFunction(probs, x => Math.Exp(x * areEqual.LogOdds));
			result.SetProbs(probs);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:24,代码来源:AreEqual.cs

示例5: LogAverageFactor

		/// <summary>
		/// Evidence message for EP.
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="selector">Incoming message from 'selector'.</param>
		/// <param name="probs">Constant value for 'probs'.</param>
		/// <returns><c>log(int f(x) qnotf(x) dx)</c></returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(int f(x) qnotf(x) dx)</c>
		/// where <c>x = (sample,selector,probs)</c>.
		/// </para></remarks>
		public static double LogAverageFactor(Discrete sample, Discrete selector, Matrix probs)
		{
			return Math.Log(probs.QuadraticForm(selector.GetProbs(), sample.GetProbs()));
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:15,代码来源:DiscreteFromDiscrete.cs

示例6: AverageLogFactor

		/// <summary>
		/// Evidence message for VMP
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <param name="probs">Incoming message from 'probs'. Must be a proper distribution.  If any element is uniform, the result will be uniform.</param>
		/// <returns>Average of the factor's log-value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>sum_(sample,probs) p(sample,probs) log(factor(sample,probs))</c>.
		/// Adding up these values across all factors and variables gives the log-evidence estimate for VMP.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		/// <exception cref="ImproperMessageException"><paramref name="probs"/> is not a proper distribution</exception>
		public static double AverageLogFactor(Discrete sample, [Proper] Dirichlet probs)
		{
			if (sample.IsPointMass)
				return AverageLogFactor(sample.Point, probs);

			if (sample.Dimension != probs.Dimension) throw new ArgumentException("sample.Dimension (" + sample.Dimension + ") != probs.Dimension (" + probs.Dimension + ")");
			Vector sampleProbs = sample.GetProbs();
			Vector pSuffStats = probs.GetMeanLog();
			// avoid multiplication of 0*log(0)
			foreach(int i in sampleProbs.IndexOfAll(v => v == 0.0)) pSuffStats[i] = 0.0;
			double total = Vector.InnerProduct(sampleProbs, pSuffStats);
			return total;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:25,代码来源:DiscreteFromDirichlet.cs

示例7: ProbsAverageLogarithm

		/// <summary>
		/// VMP message to 'probs'
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <param name="result">Modified to contain the outgoing message</param>
		/// <returns><paramref name="result"/></returns>
		/// <remarks><para>
		/// The outgoing message is the exponential of the average log-factor value, where the average is over all arguments except 'probs'.
		/// The formula is <c>exp(sum_(sample) p(sample) log(factor(sample,probs)))</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		public static Dirichlet ProbsAverageLogarithm(Discrete sample, Dirichlet result)
		{
			// E[sum_k I(X=k) log(P[k])] = sum_k p(X=k) log(P[k])
			result.TotalCount = result.Dimension + 1;
			result.PseudoCount.SetAllElementsTo(1);
			result.PseudoCount.SetToSum(result.PseudoCount, sample.GetProbs());
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:19,代码来源:DiscreteFromDirichlet.cs


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