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


C# Bernoulli类代码示例

本文整理汇总了C#中Bernoulli的典型用法代码示例。如果您正苦于以下问题:C# Bernoulli类的具体用法?C# Bernoulli怎么用?C# Bernoulli使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: AAverageConditional

 public static Bernoulli AAverageConditional(Bernoulli b, double penalty)
 {
     double penaltyFactor = Math.Exp(-penalty);
     double bProbTrue = b.GetProbTrue();
     double probTrue = (penaltyFactor * (1 - bProbTrue) + bProbTrue) / (penaltyFactor + 1);
     return new Bernoulli(probTrue);
 }
开发者ID:hr0nix,项目名称:BayesianShapePrior,代码行数:7,代码来源:GridFactors.cs

示例2: Reset

 /// <summary>
 /// Configures constant values that will not change during the lifetime of the class.
 /// </summary>
 /// <remarks>
 /// This method should be called once only after the class is instantiated.  In future, it will likely become
 /// the class constructor.
 /// </remarks>
 public void Reset()
 {
     // Create array for 'firstCoin_uses' backwards messages.
     this.firstCoin_uses_B = new Bernoulli[0];
     this.vBernoulli0 = new Bernoulli(0.5);
     this.firstCoin_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli0);
     // Message to 'firstCoin' from Random factor
     this.firstCoin_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli0);
 }
开发者ID:smokelore,项目名称:HeraAndZeus,代码行数:16,代码来源:Model_EP.cs

示例3: AverageLogFactor

		/// <summary>
		/// Evidence message for VMP.
		/// </summary>
		/// <param name="sample">Incoming message from sample</param>
		/// <param name="logOdds">Incoming message from logOdds</param>
		/// <returns><c>sum_x marginal(x)*log(factor(x))</c></returns>
		/// <remarks><para>
		/// The formula for the result is <c>int log(f(x)) q(x) dx</c>
		/// where <c>x = (sample,logOdds)</c>.
		/// </para></remarks>
		public static double AverageLogFactor(Bernoulli sample, [Proper, SkipIfUniform] Gaussian logOdds)
		{
			if (logOdds.IsUniform()) return 0.0;
			double m, v;
			logOdds.GetMeanAndVariance(out m, out v);
			double t = Math.Sqrt(m * m + v);
			double s = 2 * sample.GetProbTrue() - 1;  // probTrue - probFalse
			return MMath.LogisticLn(t) + (s * m - t) / 2;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:19,代码来源:BernoulliFromLogOdds.cs

示例4: Reset

 /// <summary>
 /// Configures constant values that will not change during the lifetime of the class.
 /// </summary>
 /// <remarks>
 /// This method should be called once only after the class is instantiated.  In future, it will likely become
 /// the class constructor.
 /// </remarks>
 public void Reset()
 {
     // Create array for 'vbool319_uses' backwards messages.
     this.vbool319_uses_B = new Bernoulli[0];
     this.vBernoulli157 = new Bernoulli(0.166666666666667);
     this.vbool319_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli157);
     // Message to 'vbool319' from Random factor
     this.vbool319_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli157);
 }
开发者ID:zhangruoxu,项目名称:pluralism,代码行数:16,代码来源:Model75_EP.cs

示例5: Infer

		public void Infer(bool[] treated, bool[] placebo)
		{
			// Set the observed values
			numberPlacebo.ObservedValue = placebo.Length;
			numberTreated.ObservedValue = treated.Length;
			placeboGroupOutcomes.ObservedValue = placebo;
			treatedGroupOutcomes.ObservedValue = treated;

			// Infer the hidden values
			posteriorTreatmentIsEffective = engine.Infer<Bernoulli>(isEffective);
			posteriorProbIfPlacebo = engine.Infer<Beta>(probIfPlacebo);
			posteriorProbIfTreated = engine.Infer<Beta>(probIfTreated);
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:13,代码来源:ClinicalTrialModel.cs

示例6: 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

示例7: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="isPositive">Incoming message from 'isPositive'.</param>
		/// <param name="x">Incoming message from 'x'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(isPositive,x) p(isPositive,x) factor(isPositive,x))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(Bernoulli isPositive, Gaussian x)
		{
			if (isPositive.IsPointMass && x.Precision == 0) {
				double tau = x.MeanTimesPrecision;
				if (isPositive.Point && tau < 0) {
					// int I(x>0) exp(tau*x) dx = -1/tau
					return -Math.Log(-tau);
				}
				if (!isPositive.Point && tau > 0) {
					// int I(x<0) exp(tau*x) dx = 1/tau
					return -Math.Log(tau);
				}
			}
			Bernoulli to_isPositive = IsPositiveAverageConditional(x);
			return isPositive.GetLogAverageOf(to_isPositive);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:25,代码来源:IsPositive.cs

示例8: GenerateData

		/// <summary>
		/// Generates a data set from a particular true model.
		/// </summary>
		public Vector[] GenerateData(int nData)
		{
			Vector trueM1 = Vector.FromArray(2.0, 3.0);
			Vector trueM2 = Vector.FromArray(7.0, 5.0);
			PositiveDefiniteMatrix trueP1 = new PositiveDefiniteMatrix(
				new double[,] { { 3.0, 0.2 }, { 0.2, 2.0 } });
			PositiveDefiniteMatrix trueP2 = new PositiveDefiniteMatrix(
				new double[,] { { 2.0, 0.4 }, { 0.4, 4.0 } });
			VectorGaussian trueVG1 = VectorGaussian.FromMeanAndPrecision(trueM1, trueP1);
			VectorGaussian trueVG2 = VectorGaussian.FromMeanAndPrecision(trueM2, trueP2);
			double truePi = 0.6;
			Bernoulli trueB = new Bernoulli(truePi);
			// Restart the infer.NET random number generator
			Rand.Restart(12347);
			Vector[] data = new Vector[nData];
			for (int j = 0; j < nData; j++) {
				bool bSamp = trueB.Sample();
				data[j] = bSamp ? trueVG1.Sample() : trueVG2.Sample();
			}
			return data;
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:24,代码来源:MixtureOfGaussians.cs

示例9: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="isPositive">Incoming message from 'isPositive'.</param>
		/// <param name="x">Incoming message from 'x'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(isPositive,x) p(isPositive,x) factor(isPositive,x))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(Bernoulli isPositive, Gaussian x)
		{
			Bernoulli to_isPositive = IsPositiveAverageConditional(x);
			return isPositive.GetLogAverageOf(to_isPositive);
#if false
			// Z = p(b=T) p(x > 0) + p(b=F) p(x <= 0)
			//   = p(b=F) + (p(b=T) - p(b=F)) p(x > 0)
			if (x.IsPointMass) {
				return Factor.IsPositive(x.Point) ? isPositive.GetLogProbTrue() : isPositive.GetLogProbFalse();
			} else if(x.IsUniform()) {
				return Bernoulli.LogProbEqual(isPositive.LogOdds,0.0);
			} else {
				// m/sqrt(v) = (m/v)/sqrt(1/v)
				double z = x.MeanTimesPrecision / Math.Sqrt(x.Precision);
				if (isPositive.IsPointMass) {
					return isPositive.Point ? MMath.NormalCdfLn(z) : MMath.NormalCdfLn(-z);
				} else {
					return MMath.LogSumExp(isPositive.GetLogProbTrue() + MMath.NormalCdfLn(z), isPositive.GetLogProbFalse() + MMath.NormalCdfLn(-z));
				}
			}
#endif
		}
开发者ID:dtrckd,项目名称:Mixed-Membership-Stochastic-Blockmodel,代码行数:31,代码来源:IsPositive.cs

示例10: Initialise

 /// <summary>
 /// Creates message arrays and initialises their values ready for inference to be performed.
 /// </summary>
 /// <remarks>
 /// This method should be called once each time inference is performed. Since the initialisation
 /// procedure normally dependson external values such as priors and array sizes, all external
 /// values must be set before calling this method.
 /// 
 /// As well as initialising message arrays, this method also performs any message passing that
 /// the scheduler determines need only be carried out once.
 /// </remarks>
 public void Initialise()
 {
     this.vbool440_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool471_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool432_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool343_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool472_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool351_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool335_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool359_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool367_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool319_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool327_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool303_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool311_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool295_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     this.vbool179_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli187);
     this.vbool171_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli179);
     this.vbool101_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli109);
     this.vbool153_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli161);
     this.vbool124_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli132);
     this.vbool88_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli96);
     this.vbool140_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli148);
     this.vbool80_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli88);
     this.vbool132_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli140);
     this.vbool28_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli36);
     this.vbool62_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli70);
     this.vbool36_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli44);
     this.vbool54_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli62);
     this.vbool10_marginal_B = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli18);
 }
开发者ID:zhangruoxu,项目名称:pluralism,代码行数:42,代码来源:Model66_EP.cs

示例11: Reset

 /// <summary>
 /// Configures constant values that will not change during the lifetime of the class.
 /// </summary>
 /// <remarks>
 /// This method should be called once only after the class is instantiated.  In future, it will likely become
 /// the class constructor.
 /// </remarks>
 public void Reset()
 {
     // Create array for 'vbool179_uses' backwards messages.
     this.vbool179_uses_B = new Bernoulli[2];
     this.vBernoulli187 = new Bernoulli(0.01);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool179_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli187);
     }
     this.vbool179_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli187);
     // Message to 'vbool179' from Random factor
     this.vbool179_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli187);
     // Create array for 'vbool171_uses' backwards messages.
     this.vbool171_uses_B = new Bernoulli[2];
     this.vBernoulli179 = new Bernoulli(0.5);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool171_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli179);
     }
     this.vbool171_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli179);
     // Message to 'vbool171' from Random factor
     this.vbool171_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli179);
     // Create array for 'vbool440_uses' backwards messages.
     this.vbool440_uses_B = new Bernoulli[1];
     for(int _ind0 = 0; _ind0<1; _ind0++)
     {
         this.vbool440_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     }
     this.vbool440_F = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     // Create array for 'vbool101_uses' backwards messages.
     this.vbool101_uses_B = new Bernoulli[2];
     this.vBernoulli109 = new Bernoulli(0.01);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool101_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli109);
     }
     this.vbool101_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli109);
     // Message to 'vbool101' from Random factor
     this.vbool101_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli109);
     // Create array for 'vbool471_uses' backwards messages.
     this.vbool471_uses_B = new Bernoulli[1];
     for(int _ind0 = 0; _ind0<1; _ind0++)
     {
         this.vbool471_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     }
     this.vbool471_F = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     // Create array for 'vbool153_uses' backwards messages.
     this.vbool153_uses_B = new Bernoulli[2];
     this.vBernoulli161 = new Bernoulli(0.01);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool153_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli161);
     }
     this.vbool153_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli161);
     // Message to 'vbool153' from Random factor
     this.vbool153_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli161);
     // Create array for 'vbool432_uses' backwards messages.
     this.vbool432_uses_B = new Bernoulli[1];
     for(int _ind0 = 0; _ind0<1; _ind0++)
     {
         this.vbool432_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     }
     this.vbool432_F = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     // Create array for 'vbool124_uses' backwards messages.
     this.vbool124_uses_B = new Bernoulli[2];
     this.vBernoulli132 = new Bernoulli(0.5);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool124_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli132);
     }
     this.vbool124_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli132);
     // Message to 'vbool124' from Random factor
     this.vbool124_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli132);
     // Create array for 'vbool343_uses' backwards messages.
     this.vbool343_uses_B = new Bernoulli[1];
     for(int _ind0 = 0; _ind0<1; _ind0++)
     {
         this.vbool343_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     }
     this.vbool343_F = ArrayHelper.MakeUniform<Bernoulli>(new Bernoulli());
     // Create array for 'vbool88_uses' backwards messages.
     this.vbool88_uses_B = new Bernoulli[2];
     this.vBernoulli96 = new Bernoulli(0.01);
     for(int _ind0 = 0; _ind0<2; _ind0++)
     {
         this.vbool88_uses_B[_ind0] = ArrayHelper.MakeUniform<Bernoulli>(this.vBernoulli96);
     }
     this.vbool88_F = ArrayHelper.MakeUniform<Bernoulli>(vBernoulli96);
     // Message to 'vbool88' from Random factor
     this.vbool88_F = UnaryOp<bool>.RandomAverageConditional<Bernoulli>(this.vBernoulli96);
     // Create array for 'vbool472_uses' backwards messages.
     this.vbool472_uses_B = new Bernoulli[1];
     for(int _ind0 = 0; _ind0<1; _ind0++)
//.........这里部分代码省略.........
开发者ID:zhangruoxu,项目名称:pluralism,代码行数:101,代码来源:Model66_EP.cs

示例12: LogAverageFactor

		/// <summary>
		/// Evidence message for EP
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'.</param>
		/// <param name="to_sample">Outgoing message to 'sample'.</param>
		/// <returns>Logarithm of the factor's average value across the given argument distributions</returns>
		/// <remarks><para>
		/// The formula for the result is <c>log(sum_(sample) p(sample) factor(sample,probTrue))</c>.
		/// </para></remarks>
		public static double LogAverageFactor(Bernoulli sample, [Fresh] Bernoulli to_sample)
		{
			return sample.GetLogAverageOf(to_sample);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:13,代码来源:BernoulliFromBeta.cs

示例13: LogEvidenceRatio

		public static double LogEvidenceRatio(Bernoulli sample, double probTrue)
		{
			return 0.0;
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:4,代码来源:BernoulliFromBeta.cs

示例14: Update

 /// <summary>
 /// Performs one iteration of inference.
 /// </summary>
 /// <remarks>
 /// This method should be called multiple times, after calling Initialise(), in order to perform
 /// multiple iterations of message passing.  You can call methods to retrieve posterior marginals
 /// at any time - the returned marginal will be the estimated marginal given the current state of
 /// the message passing algorithm.  This can be useful for monitoring convergence of the algorithm.
 /// 
 /// Where the scheduler has determined inference can be performed without iteration, this method
 /// does nothing.
 /// </remarks>
 public void Update()
 {
     // Message to 'vbool111_uses' from And factor
     this.vbool111_uses_B[2] = BooleanAndOp.AAverageConditional(this.vbool287_B, this.vbool116_uses_F[0]);
     // Message to 'vbool111_uses' from UsesEqualDef factor
     this.vbool111_uses_F[0] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool111_uses_B, this.vbool111_F, 0, this.vbool111_uses_F[0]);
     // Message to 'vbool103_uses' from AreEqual factor
     this.vbool103_uses_B[1] = BooleanAreEqualOp.BAverageConditional(this.vbool194_B, this.vbool111_uses_F[0]);
     // Message to 'vbool103_uses' from UsesEqualDef factor
     this.vbool103_uses_F[0] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool103_uses_B, this.vbool103_F, 0, this.vbool103_uses_F[0]);
     // Message to 'vbool181_uses' from AreEqual factor
     this.vbool181_uses_B[2] = BooleanAreEqualOp.BAverageConditional(this.vbool446_B, this.vbool103_uses_F[0]);
     // Message to 'vbool181_uses' from UsesEqualDef factor
     this.vbool181_uses_F[0] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool181_uses_B, this.vbool181_F, 0, this.vbool181_uses_F[0]);
     // Message to 'vbool163_uses' from AreEqual factor
     this.vbool163_uses_B[0] = BooleanAreEqualOp.BAverageConditional(this.vbool420_B, this.vbool181_uses_F[0]);
     // Message to 'vbool163_uses' from UsesEqualDef factor
     this.vbool163_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool163_uses_B, this.vbool163_F, 1, this.vbool163_uses_F[1]);
     // Message to 'vbool155_uses' from AreEqual factor
     this.vbool155_uses_B[1] = BooleanAreEqualOp.BAverageConditional(this.vbool419_B, this.vbool163_uses_F[1]);
     // Message to 'vbool155_uses' from UsesEqualDef factor
     this.vbool155_uses_F[0] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool155_uses_B, this.vbool155_F, 0, this.vbool155_uses_F[0]);
     // Message to 'vbool181_uses' from AreEqual factor
     this.vbool181_uses_B[1] = BooleanAreEqualOp.AAverageConditional(this.vbool441_B, this.vbool155_uses_F[0]);
     // Message to 'vbool181_uses' from UsesEqualDef factor
     this.vbool181_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool181_uses_B, this.vbool181_F, 1, this.vbool181_uses_F[1]);
     // Message to 'vbool155_uses' from AreEqual factor
     this.vbool155_uses_B[0] = BooleanAreEqualOp.BAverageConditional(this.vbool441_B, this.vbool181_uses_F[1]);
     // Message to 'vbool441' from AreEqual factor
     this.vbool441_F = BooleanAreEqualOp.AreEqualAverageConditional(this.vbool181_uses_F[1], this.vbool155_uses_F[0]);
     // Message to 'vbool441_marginal' from ReplicateWithMarginal factor
     this.vbool441_marginal_B = ReplicateOp.MarginalAverageConditional<Bernoulli>(this.vbool441_uses_B, this.vbool441_F, this.vbool441_marginal_B);
     // Message to 'vbool155_uses' from UsesEqualDef factor
     this.vbool155_uses_F[2] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool155_uses_B, this.vbool155_F, 2, this.vbool155_uses_F[2]);
     // Message to 'vbool90_uses' from AreEqual factor
     this.vbool90_uses_B[0] = BooleanAreEqualOp.AAverageConditional(this.vbool451_B, this.vbool155_uses_F[2]);
     // Message to 'vbool90_uses' from UsesEqualDef factor
     this.vbool90_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool90_uses_B, this.vbool90_F, 1, this.vbool90_uses_F[1]);
     // Message to 'vbool72_uses' from AreEqual factor
     this.vbool72_uses_B[0] = BooleanAreEqualOp.BAverageConditional(this.vbool210_B, this.vbool90_uses_F[1]);
     // Message to 'vbool72_uses' from UsesEqualDef factor
     this.vbool72_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool72_uses_B, this.vbool72_F, 1, this.vbool72_uses_F[1]);
     // Message to 'vbool155_uses' from UsesEqualDef factor
     this.vbool155_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool155_uses_B, this.vbool155_F, 1, this.vbool155_uses_F[1]);
     // Message to 'vbool163_uses' from AreEqual factor
     this.vbool163_uses_B[1] = BooleanAreEqualOp.AAverageConditional(this.vbool419_B, this.vbool155_uses_F[1]);
     // Message to 'vbool163_marginal' from UsesEqualDef factor
     this.vbool163_marginal_B = UsesEqualDefOp.MarginalAverageConditional<Bernoulli>(this.vbool163_uses_B, this.vbool163_F, this.vbool163_marginal_B);
     // Message to 'vbool419' from AreEqual factor
     this.vbool419_F = BooleanAreEqualOp.AreEqualAverageConditional(this.vbool163_uses_F[1], this.vbool155_uses_F[1]);
     // Message to 'vbool419_marginal' from ReplicateWithMarginal factor
     this.vbool419_marginal_B = ReplicateOp.MarginalAverageConditional<Bernoulli>(this.vbool419_uses_B, this.vbool419_F, this.vbool419_marginal_B);
     // Message to 'vbool163_uses' from UsesEqualDef factor
     this.vbool163_uses_F[0] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool163_uses_B, this.vbool163_F, 0, this.vbool163_uses_F[0]);
     // Message to 'vbool181_uses' from AreEqual factor
     this.vbool181_uses_B[0] = BooleanAreEqualOp.AAverageConditional(this.vbool420_B, this.vbool163_uses_F[0]);
     // Message to 'vbool181_marginal' from UsesEqualDef factor
     this.vbool181_marginal_B = UsesEqualDefOp.MarginalAverageConditional<Bernoulli>(this.vbool181_uses_B, this.vbool181_F, this.vbool181_marginal_B);
     // Message to 'vbool420' from AreEqual factor
     this.vbool420_F = BooleanAreEqualOp.AreEqualAverageConditional(this.vbool181_uses_F[0], this.vbool163_uses_F[0]);
     // Message to 'vbool420_marginal' from ReplicateWithMarginal factor
     this.vbool420_marginal_B = ReplicateOp.MarginalAverageConditional<Bernoulli>(this.vbool420_uses_B, this.vbool420_F, this.vbool420_marginal_B);
     // Message to 'vbool181_uses' from UsesEqualDef factor
     this.vbool181_uses_F[2] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool181_uses_B, this.vbool181_F, 2, this.vbool181_uses_F[2]);
     // Message to 'vbool103_uses' from AreEqual factor
     this.vbool103_uses_B[0] = BooleanAreEqualOp.AAverageConditional(this.vbool446_B, this.vbool181_uses_F[2]);
     // Message to 'vbool103_marginal' from UsesEqualDef factor
     this.vbool103_marginal_B = UsesEqualDefOp.MarginalAverageConditional<Bernoulli>(this.vbool103_uses_B, this.vbool103_F, this.vbool103_marginal_B);
     // Message to 'vbool446' from AreEqual factor
     this.vbool446_F = BooleanAreEqualOp.AreEqualAverageConditional(this.vbool103_uses_F[0], this.vbool181_uses_F[2]);
     // Message to 'vbool446_marginal' from ReplicateWithMarginal factor
     this.vbool446_marginal_B = ReplicateOp.MarginalAverageConditional<Bernoulli>(this.vbool446_uses_B, this.vbool446_F, this.vbool446_marginal_B);
     // Message to 'vbool103_uses' from UsesEqualDef factor
     this.vbool103_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool103_uses_B, this.vbool103_F, 1, this.vbool103_uses_F[1]);
     // Message to 'vbool111_uses' from AreEqual factor
     this.vbool111_uses_B[0] = BooleanAreEqualOp.AAverageConditional(this.vbool194_B, this.vbool103_uses_F[1]);
     // Message to 'vbool194' from AreEqual factor
     this.vbool194_F = BooleanAreEqualOp.AreEqualAverageConditional(this.vbool111_uses_F[0], this.vbool103_uses_F[1]);
     // Message to 'vbool194_marginal' from ReplicateWithMarginal factor
     this.vbool194_marginal_B = ReplicateOp.MarginalAverageConditional<Bernoulli>(this.vbool194_uses_B, this.vbool194_F, this.vbool194_marginal_B);
     // Message to 'vbool111_uses' from UsesEqualDef factor
     this.vbool111_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool111_uses_B, this.vbool111_F, 1, this.vbool111_uses_F[1]);
     // Message to 'vbool111_uses' from UsesEqualDef factor
     this.vbool111_uses_F[2] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool111_uses_B, this.vbool111_F, 2, this.vbool111_uses_F[2]);
     // Message to 'vbool116_uses' from And factor
     this.vbool116_uses_B[0] = BooleanAndOp.BAverageConditional(this.vbool287_B, this.vbool111_uses_F[2]);
     // Message to 'vbool116_uses' from UsesEqualDef factor
     this.vbool116_uses_F[1] = UsesEqualDefOp.UsesAverageConditional<Bernoulli>(this.vbool116_uses_B, this.vbool116_F, 1, this.vbool116_uses_F[1]);
//.........这里部分代码省略.........
开发者ID:zhangruoxu,项目名称:pluralism,代码行数:101,代码来源:Model71_EP.cs

示例15: ProbTrueAverageLogarithm

		/// <summary>
		/// VMP message to 'probTrue'
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <returns>The outgoing VMP message to the 'probTrue' argument</returns>
		/// <remarks><para>
		/// The outgoing message is the exponential of the average log-factor value, where the average is over all arguments except 'probTrue'.
		/// The formula is <c>exp(sum_(sample) p(sample) log(factor(sample,probTrue)))</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		public static Beta ProbTrueAverageLogarithm(Bernoulli sample)
		{
			// E[x*log(p) + (1-x)*log(1-p)] = E[x]*log(p) + (1-E[x])*log(1-p)
			double ex = sample.GetProbTrue();
			return new Beta(1 + ex, 2 - ex);
		}
开发者ID:prgoodwin,项目名称:HabilisX,代码行数:16,代码来源:BernoulliFromBeta.cs


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