public virtual void Test(double tolerance) { double p1 = _dist.CDF(_a[2]); Assert.AreEqual(_a[3], p1, Math.Abs(_a[3] * tolerance), "Unexpected result of CDF"); double d1 = _dist.PDF(_a[2]); Assert.AreEqual(_a[4], d1, Math.Abs(_a[4] * tolerance), "Unexpected result of PDF"); int len = 1000000; int suml = 0; for (int i = 0; i < len; i++) { if (_dist.NextDouble() <= _a[2]) { suml++; } } double p1_tested = suml / (double)len; double confidence = BinomialDistribution.CDF(suml, _a[3], len); Assert.Greater(confidence, 0.01, string.Format("Unexpected result of distribution of generated values : outside (left) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", _a[3], p1_tested, confidence)); Assert.Less(confidence, 0.99, string.Format("Unexpected result of distribution of generated values : outside (right) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", _a[3], p1_tested, confidence)); }
public virtual void Test(double tolerance) { // a0 and a1 are the distribution parameters // Test quantile double x1 = _dist.Quantile(firstProb); Assert.AreEqual(_a[2], x1, Math.Abs(_a[2] * tolerance), "Unexpected result of Quantile firstProb"); double p1 = _dist.CDF(_a[2]); Assert.AreEqual(firstProb, p1, Math.Abs(firstProb * tolerance), "Unexpected result of CDF firstQuantile"); double d1 = _dist.PDF(_a[2]); Assert.AreEqual(_a[3], d1, Math.Abs(_a[3] * tolerance), "Unexpected result of PDF firstQuantile"); double x2 = _dist.Quantile(secondProb); Assert.AreEqual(_a[4], x2, Math.Abs(_a[4] * tolerance), "Unexpected result of Quantile secondProb"); double p2 = _dist.CDF(_a[4]); Assert.AreEqual(secondProb, p2, Math.Abs(secondProb * tolerance), "Unexpected result of CDF secondQuantile"); double d2 = _dist.PDF(_a[4]); Assert.AreEqual(_a[5], d2, Math.Abs(_a[5] * tolerance), "Unexpected result of PDF secondQuantile"); int len = 1000000; int suml = 0; for (int i = 0; i < len; i++) { if (_dist.NextDouble() < _a[2]) { suml++; } } double p1_tested = suml / (double)len; double confidence = BinomialDistribution.CDF(suml, firstProb, len); Assert.Greater(confidence, 0.01, string.Format("Unexpected result of distribution of generated values : outside (left) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", firstProb, p1_tested, confidence)); Assert.Less(confidence, 0.99, string.Format("Unexpected result of distribution of generated values : outside (right) the 1% confidence limits, expected p={0}, actual p={1}, confidence={2}", firstProb, p1_tested, confidence)); }