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


C# Gaussian.SetToProduct方法代码示例

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


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

示例1: UsesAverageLogarithm

 public static Gaussian UsesAverageLogarithm(NonconjugateGaussian[] Uses, Gaussian Def, Gaussian result)
 {
     NonconjugateGaussian prod = Uses[0];
     for (int i = 1; i < Uses.Length; i++)
         prod.SetToProduct(prod, Uses[i]);
     result = prod.GetGaussian(true);
     result.SetToProduct(result, Def);
     return result;
 }
开发者ID:xornand,项目名称:Infer.Net,代码行数:9,代码来源:NonconjugateUsesEqualDef.cs

示例2: LogisticProposalDistribution

		/// <summary>
		/// Find the Laplace approximation for Beta(Logistic(x)) * Gaussian(x))
		/// </summary>
		/// <param name="beta">Beta distribution</param>
		/// <param name="gauss">Gaussian distribution</param>
		/// <returns>A proposal distribution</returns>
		public static Gaussian LogisticProposalDistribution(Beta beta, Gaussian gauss)
		{
			if (beta.IsUniform())
				return new Gaussian(gauss);

			// if gauss is uniform, m,p = 0 below, and the following code will just ignore the Gaussian
			// and do a Laplace approximation for Beta(Logistic(x))

			double c = beta.TrueCount-1;
			double d = beta.FalseCount-1;
			double m = gauss.GetMean();
			double p = gauss.Precision;
			// We want to find the mode of
			// ln(g(x)) = c.ln(f(x)) + d.ln(1 - f(x)) - 0.5p((x - m)^2) + constant
			// First deriv:
			// h(x) = (ln(g(x))' = c.(1 - f(x)) - d.f(x) - p(x-m)
			// Second deriv:
			// h'(x) = (ln(g(x))' = -(c+d).f'(x) - p
			// Use Newton-Raphson to find unique root of h(x).
			// g(x) is log-concave so Newton-Raphson should converge quickly.
			// Set the initial point by projecting beta
			// to a Gaussian and taking the mean of the product:
			double bMean, bVar;
			beta.GetMeanAndVariance(out bMean, out bVar);
			Gaussian prod = new Gaussian();
			double invLogisticMean = Math.Log(bMean) - Math.Log(1.0-bMean);
			prod.SetToProduct(Gaussian.FromMeanAndVariance(invLogisticMean, bVar), gauss);
			double xnew = prod.GetMean();
			double x=0, fx, dfx, hx, dhx=0;
			int maxIters = 100; // Should only need a handful of iters
			int cnt = 0;
			do {
				x = xnew;
				fx = MMath.Logistic(x);
				dfx = fx * (1.0-fx);
				// Find the root of h(x)
				hx = c * (1.0 - fx) - d * fx - p*(x-m);
				dhx = -(c+d)*dfx - p;
				xnew = x - (hx / dhx); // The Newton step
				if (Math.Abs(x - xnew) < 0.00001)
					break;
			} while (++cnt < maxIters);
			if (cnt >= maxIters)
				throw new ApplicationException("Unable to find proposal distribution mode");
			return Gaussian.FromMeanAndPrecision(x, -dhx);
		}
开发者ID:xornand,项目名称:Infer.Net,代码行数:52,代码来源:ProductGaussianBeta.cs


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