本文整理汇总了C#中Gaussian.Sample方法的典型用法代码示例。如果您正苦于以下问题:C# Gaussian.Sample方法的具体用法?C# Gaussian.Sample怎么用?C# Gaussian.Sample使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaussian
的用法示例。
在下文中一共展示了Gaussian.Sample方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Weights
public static Vector Weights(Gaussian A, Gaussian B, Gaussian to_A, Gaussian to_B)
{
if (A.IsPointMass) return Weights(A.Point, B);
if (B.IsPointMass) return Weights(A, B.Point);
A *= to_A;
B *= to_B;
double ma, va, mb, vb;
A.GetMeanAndVariance(out ma, out va);
B.GetMeanAndVariance(out mb, out vb);
double ma2 = va + ma*ma;
double mb2 = vb + mb*mb;
Vector w = Vector.Zero(3);
w[0] = ma2*mb;
w[1] = mb2*ma;
w[2] = ma*mb;
PositiveDefiniteMatrix M = new PositiveDefiniteMatrix(3, 3);
M[0, 0] = ma2;
M[0, 1] = ma*mb;
M[0, 2] = ma;
M[1, 0] = ma*mb;
M[1, 1] = mb2;
M[1, 2] = mb;
M[2, 0] = ma;
M[2, 1] = mb;
M[2, 2] = 1;
w = w.PredivideBy(M);
Vector weights = Vector.Zero(4);
weights[0] = w[0];
weights[1] = w[1];
weights[2] = w[2];
weights[3] = ma2*mb2 - w[0]*ma2*mb - w[1]*mb2*ma - w[2]*ma*mb;
if (weights[3] < 0) weights[3] = 0;
if (false) {
// debugging
GaussianEstimator est = new GaussianEstimator();
for (int i = 0; i < 10000; i++) {
double sa = A.Sample();
double sb = B.Sample();
double f = sa*sb;
double g = sa*weights[0] + sb*weights[1] + weights[2];
est.Add(f-g);
}
Console.WriteLine(weights);
Console.WriteLine(est.GetDistribution(new Gaussian()));
}
return weights;
}
示例2: Sample
public int[][] Sample(int nSubjects, int nQuestions, int nChoices, Gaussian abilityPrior, Gaussian difficultyPrior, Gamma discriminationPrior,
out double[] ability, out double[] difficulty, out double[] discrimination, out int[] trueAnswer)
{
ability = Util.ArrayInit(nSubjects, s => abilityPrior.Sample());
difficulty = Util.ArrayInit(nQuestions, q => difficultyPrior.Sample());
discrimination = Util.ArrayInit(nQuestions, q => discriminationPrior.Sample());
trueAnswer = Util.ArrayInit(nQuestions, q => Rand.Int(nChoices));
int[][] response = new int[nSubjects][];
for (int s = 0; s < nSubjects; s++) {
response[s] = new int[nQuestions];
for (int q = 0; q < nQuestions; q++) {
double advantage = ability[s] - difficulty[q];
double noise = Gaussian.Sample(0, discrimination[q]);
bool correct = (advantage > noise);
if (correct) response[s][q] = trueAnswer[q];
else response[s][q] = Rand.Int(nChoices);
}
}
return response;
}