本文整理汇总了C#中Gaussian.IsProper方法的典型用法代码示例。如果您正苦于以下问题:C# Gaussian.IsProper方法的具体用法?C# Gaussian.IsProper怎么用?C# Gaussian.IsProper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaussian
的用法示例。
在下文中一共展示了Gaussian.IsProper方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleAverageConditional
public static Gaussian SampleAverageConditional(Gaussian sample, [SkipIfUniform] Gaussian mean, [Proper] Gamma variance)
{
if (variance.IsPointMass) return SampleAverageConditional(mean, variance.Point);
if (mean.IsUniform()) return Gaussian.Uniform();
double mx,vx,mm,vm;
double a,b;
sample.GetMeanAndVariance(out mx, out vx);
mean.GetMeanAndVariance(out mm, out vm);
a = variance.Shape;
b = variance.Rate;
if (sample.IsUniform()) return new Gaussian(mm, vm + a/b);
double c = Math.Sqrt(2*b);
double m = c*(mx-mm);
double v = c*c*(vx+vm);
double mu,vu;
if(a < 1) throw new ArgumentException("variance.shape < 1");
double m2p = m*m/v;
if (false && Math.Abs(m*m/v) > 30) {
double invV = 1/v;
double invSqrtV = Math.Sqrt(invV);
double mPlus = (m-v)*invSqrtV;
double mMinus = (-m-v)*invSqrtV;
double Zplus = MMath.NormalCdfRatio(mPlus);
double Zminus = MMath.NormalCdfRatio(mMinus);
double Z0 = Zminus + Zplus;
double alpha = (Zminus - Zplus)/Z0;
double beta = -(1 - 2/Z0*invSqrtV - alpha*alpha);
alpha *= c;
beta *= c*c;
double weight = beta / (sample.Precision - beta);
Gaussian result = new Gaussian();
result.Precision = sample.Precision * weight;
result.MeanTimesPrecision = weight * (sample.MeanTimesPrecision + alpha) + alpha;
if (!result.IsProper()) throw new ImproperMessageException(result);
if (double.IsNaN(result.Precision) || double.IsNaN(result.MeanTimesPrecision)) throw new ApplicationException("result is nan");
return result;
} else {
//double logZ;
//if(a == 1) LaplacianTimesGaussianMoments(m, v, out logZ, out mu, out vu);
VarianceGammaTimesGaussianMoments5(a, m, v, out mu, out vu);
//Console.WriteLine("mu = {0}, vu = {1}", mu, vu);
//VarianceGammaTimesGaussianMoments(a, m, v, out mu, out vu);
//Console.WriteLine("mu = {0}, vu = {1}", mu, vu);
double r = vx/(vx+vm);
double mp = r*(mu/c + mm) + (1-r)*mx;
double vp = r*r*vu/(c*c) + r*vm;
if (Double.IsNaN(vp)) throw new Exception("vp is NaN");
Gaussian result = Gaussian.FromMeanAndVariance(mp, vp)/sample;
if (!result.IsProper()) throw new ImproperMessageException(result);
return result;
}
}
开发者ID:dtrckd,项目名称:Mixed-Membership-Stochastic-Blockmodel,代码行数:52,代码来源:GaussianFromMeanAndVariance.cs