當前位置: 首頁>>代碼示例>>C#>>正文


C# Beta.GetMeanSquare方法代碼示例

本文整理匯總了C#中Beta.GetMeanSquare方法的典型用法代碼示例。如果您正苦於以下問題:C# Beta.GetMeanSquare方法的具體用法?C# Beta.GetMeanSquare怎麽用?C# Beta.GetMeanSquare使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Beta的用法示例。


在下文中一共展示了Beta.GetMeanSquare方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProbTrueAverageConditional

		/// <summary>
		/// EP message to 'probTrue'
		/// </summary>
		/// <param name="sample">Incoming message from 'sample'. Must be a proper distribution.  If uniform, the result will be uniform.</param>
		/// <param name="probTrue">Incoming message from 'probTrue'.</param>
		/// <returns>The outgoing EP message to the 'probTrue' argument</returns>
		/// <remarks><para>
		/// The outgoing message is a distribution matching the moments of 'probTrue' as the random arguments are varied.
		/// The formula is <c>proj[p(probTrue) sum_(sample) p(sample) factor(sample,probTrue)]/p(probTrue)</c>.
		/// </para></remarks>
		/// <exception cref="ImproperMessageException"><paramref name="sample"/> is not a proper distribution</exception>
		public static Beta ProbTrueAverageConditional([SkipIfUniform] Bernoulli sample, Beta probTrue)
		{
			// this code is similar to DiscreteFromDirichletOp.PAverageConditional()
			if (probTrue.IsPointMass) {
				return Beta.Uniform();
			}
			if (sample.IsPointMass) {
				// shortcut
				return ProbTrueConditional(sample.Point);
			}
			if (!probTrue.IsProper()) throw new ImproperMessageException(probTrue);
			// q(x) is the distribution stored in this.X.
			// q(p) is the distribution stored in this.P.
			// f(x,p) is the factor.
			// Z = sum_x q(x) int_p f(x,p)*q(p) = q(false)*E[1-p] + q(true)*E[p]
			// Ef[p] = 1/Z sum_x q(x) int_p p*f(x,p)*q(p) = 1/Z (q(false)*E[p(1-p)] + q(true)*E[p^2])
			// Ef[p^2] = 1/Z sum_x q(x) int_p p^2*f(x,p)*q(p) = 1/Z (q(false)*E[p^2(1-p)] + q(true)*E[p^3])
			// var_f(p) = Ef[p^2] - Ef[p]^2
			double mo = probTrue.GetMean();
			double m2o = probTrue.GetMeanSquare();
			double pT = sample.GetProbTrue();
			double pF = sample.GetProbFalse();
			double Z = pF * (1 - mo) + pT * mo;
			double m = pF * (mo - m2o) + pT * m2o;
			m = m / Z;
			if (!Beta.AllowImproperSum) {
				if (pT < 0.5) {
					double inc = probTrue.TotalCount * (mo / m - 1);
					return new Beta(1, 1 + inc);
				} else {
					double inc = probTrue.TotalCount * ((1 - mo) / (1 - m) - 1);
					return new Beta(1 + inc, 1);
				}
			} else {
				double m3o = probTrue.GetMeanCube();
				double m2 = pF * (m2o - m3o) + pT * m3o;
				m2 = m2 / Z;
				Beta result = Beta.FromMeanAndVariance(m, m2 - m * m);
				result.SetToRatio(result, probTrue);
				return result;
			}
		}
開發者ID:prgoodwin,項目名稱:HabilisX,代碼行數:53,代碼來源:BernoulliFromBeta.cs


注:本文中的Beta.GetMeanSquare方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。