public void P2QuantileEstimatorTest(string testKey) { var testData = TestDataMap[testKey]; double p = testData.Probability; var sample = testData.Generate(); var estimator = new P2QuantileEstimator(p); foreach (double x in sample.Values) { estimator.AddValue(x); } double actual = estimator.GetQuantile(); double expected = SimpleQuantileEstimator.Instance.GetQuantile(sample, p); double pDelta = 0.1 + Math.Abs(p - 0.5) * 0.2 + 2.0 / testData.N; double expectedMin = SimpleQuantileEstimator.Instance.GetQuantile(sample, (p - pDelta).Clamp(0, 1)); double expectedMax = SimpleQuantileEstimator.Instance.GetQuantile(sample, (p + pDelta).Clamp(0, 1)); double mad = MedianAbsoluteDeviation.CalcMad(sample); double error = Math.Abs(actual - expected); double errorNorm = error / mad; output.WriteLine($"ExpectedMin = {expectedMin:N5}"); output.WriteLine($"Expected = {expected:N5}"); output.WriteLine($"ExpectedMax = {expectedMax:N5}"); output.WriteLine($"Actual = {actual:N5}"); output.WriteLine($"Error = {error:N5}"); output.WriteLine($"ErrorNorm = {errorNorm:N5}"); Assert.True(expectedMin <= actual && actual <= expectedMax); }
public void P2QuantileEstimatorReferenceTest() { double[] values = { 0.02, 0.15, 0.74, 3.39, 0.83, 22.37, 10.15, 15.43, 38.62, 15.92, 34.60, 10.28, 1.47, 0.40, 0.05, 11.39, 0.27, 0.42, 0.09, 11.37 }; var estimator = new P2QuantileEstimator(0.5); foreach (double x in values) { estimator.AddValue(x); } double actual = estimator.GetQuantile(); const double expected = 4.44; Assert.Equal(expected, actual, new AbsoluteEqualityComparer(1e-2)); }