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


C# Bernoulli.SetProbTrue方法代码示例

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


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

示例1: ChoiceConditional

        /// <summary>
        /// Gibbs message to 'choice'.
        /// </summary>
        /// <param name="sample">Constant value for 'sample'.</param>
        /// <param name="probTrue0">Constant value for 'probTrue0'.</param>
        /// <param name="probTrue1">Constant value for 'probTrue1'.</param>
        /// <returns>The outgoing Gibbs message to the 'choice' argument.</returns>
        /// <remarks><para>
        /// The outgoing message is the factor viewed as a function of 'choice' conditioned on the given values.
        /// </para></remarks>
		public static Bernoulli ChoiceConditional(bool sample, double probTrue0, double probTrue1)
		{
            Bernoulli result = new Bernoulli();
			if (probTrue0 == 0 || probTrue1 == 0) throw new ArgumentException("probTrue is zero");
			if (sample) {
				double sum = probTrue0 + probTrue1;
				if(sum == 0.0) throw new AllZeroException();
				else result.SetProbTrue(probTrue1 / sum);
			} else {
				double sum = 2 - probTrue1 - probTrue0;
				if(sum == 0.0) throw new AllZeroException();
				else result.SetProbTrue((1 - probTrue1) / sum);
			}
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:25,代码来源:BernoulliFromBoolean.cs

示例2: SampleConditional

        /// <summary>
        /// Gibbs message to 'sample'.
        /// </summary>
        /// <param name="choice">Constant value for 'choice'.</param>
        /// <param name="probTrue0">Constant value for 'probTrue0'.</param>
        /// <param name="probTrue1">Constant value for 'probTrue1'.</param>
        /// <returns>The outgoing Gibbs message to the 'sample' argument.</returns>
        /// <remarks><para>
        /// The outgoing message is the factor viewed as a function of 'sample' conditioned on the given values.
        /// </para></remarks>
        public static Bernoulli SampleConditional(bool choice, double probTrue0, double probTrue1)
		{
            Bernoulli result = new Bernoulli();
			result.SetProbTrue(choice ? probTrue1 : probTrue0);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:16,代码来源:BernoulliFromBoolean.cs

示例3: ChoiceAverageConditional

        /// <summary>
        /// EP message to 'choice'.
        /// </summary>
        /// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
        /// <param name="probTrue0">Constant value for 'probTrue0'.</param>
        /// <param name="probTrue1">Constant value for 'probTrue1'.</param>
        /// <returns>The outgoing EP message to the 'choice' argument.</returns>
        /// <remarks><para>
        /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'choice'.
        /// The formula is <c>int f(choice,x) q(x) dx</c> where <c>x = (sample,probTrue0,probTrue1)</c>.
        /// </para></remarks>
        /// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		public static Bernoulli ChoiceAverageConditional([SkipIfUniform] Bernoulli sample, double probTrue0, double probTrue1)
		{
            Bernoulli result = new Bernoulli();
			if(sample.IsPointMass) return ChoiceConditional(sample.Point,probTrue0,probTrue1);
#if FAST
			double p1 = sample.GetProbFalse() * (1 - probTrue1) + sample.GetProbTrue() * probTrue1;
			double p0 = sample.GetProbFalse() * (1 - probTrue0) + sample.GetProbTrue() * probTrue0;
			double sum = p0+p1;
			if(sum == 0.0) throw new AllZeroException();
			else result.SetProbTrue(p1 / sum);
#else
			// This method is more numerically stable but slower.
			// ax = log(FT/TT)
			// bx = log(FF/TF)
			// offset = log(TT/TF)
			if (probTrue0 == 0 || probTrue1 == 0) throw new ArgumentException("probTrue is zero");
			double ax = -MMath.Logit(probTrue1);
			double bx = -MMath.Logit(probTrue0);
			double offset = Math.Log(probTrue1 / probTrue0);
			result.LogOdds = MMath.DiffLogSumExp(sample.LogOdds, ax, bx) + offset;
#endif
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:35,代码来源:BernoulliFromBoolean.cs

示例4: SampleAverageConditional

        /// <summary>
        /// EP message to 'sample'.
        /// </summary>
        /// <param name="choice">Incoming message from 'choice'.</param>
        /// <param name="probTrue0">Constant value for 'probTrue0'.</param>
        /// <param name="probTrue1">Constant value for 'probTrue1'.</param>
        /// <returns>The outgoing EP message to the 'sample' argument.</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 = (choice,probTrue0,probTrue1)</c>.
        /// </para></remarks>
        public static Bernoulli SampleAverageConditional(Bernoulli choice, double probTrue0, double probTrue1)
		{
            Bernoulli result = new Bernoulli();
			if(choice.IsPointMass) return SampleConditional(choice.Point,probTrue0,probTrue1);
#if FAST
			result.SetProbTrue(choice.GetProbFalse() * probTrue0 + choice.GetProbTrue() * probTrue1);
#else
			// This method is more numerically stable but slower.
			// let oX = log(p(X)/(1-p(X))
			// let oY = log(p(Y)/(1-p(Y))
			// oX = log( (TT*sigma(oY) + TF*sigma(-oY))/(FT*sigma(oY) + FF*sigma(-oY)) )
			//    = log( (TT*exp(oY) + TF)/(FT*exp(oY) + FF) )
			//    = log( (exp(oY) + TF/TT)/(exp(oY) + FF/FT) ) + log(TT/FT)
			// ay = log(TF/TT)
			// by = log(FF/FT)
			// offset = log(TT/FT)
			if (probTrue0 == 0 || probTrue1 == 0) throw new ArgumentException("probTrue is zero");
			double ay = Math.Log(probTrue0 / probTrue1);
			double by = Math.Log((1 - probTrue0) / (1 - probTrue1));
			double offset = MMath.Logit(probTrue1);
			result.LogOdds = MMath.DiffLogSumExp(choice.LogOdds, ay, by) + offset;
#endif
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:35,代码来源:BernoulliFromBoolean.cs

示例5: SampleConditional

		/// <summary>
		/// Gibbs message to 'sample'.
		/// </summary>
		/// <param name="index">Constant value for 'index'.</param>
		/// <param name="ProbTrue">Constant value for 'probTrue'.</param>
		/// <returns>The outgoing Gibbs message to the 'sample' argument.</returns>
		/// <remarks><para>
		/// The outgoing message is the factor viewed as a function of 'sample' conditioned on the given values.
		/// </para></remarks>
		public static Bernoulli SampleConditional(int index, double[] ProbTrue)
		{
			Bernoulli result = new Bernoulli();
			result.SetProbTrue(ProbTrue[index]);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:15,代码来源:BernoulliFromDiscrete.cs

示例6: SampleAverageConditional

		/// <summary>
		/// EP message to 'sample'.
		/// </summary>
		/// <param name="index">Incoming message from 'index'.</param>
		/// <param name="ProbTrue">Constant value for 'probTrue'.</param>
		/// <returns>The outgoing EP message to the 'sample' argument.</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 = (index,probTrue)</c>.
		/// </para></remarks>
		public static Bernoulli SampleAverageConditional(Discrete index, double[] ProbTrue)
		{
			Bernoulli result = new Bernoulli();
			// E[X] = sum_Y p(Y) ProbTrue[Y]
			double p = 0;
			for (int i = 0; i < index.Dimension; i++)
			{
				p += ProbTrue[i] * index[i];
			}
			result.SetProbTrue(p);
			return result;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:22,代码来源:BernoulliFromDiscrete.cs


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