You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/12/11 08:43:54 UTC
[commons-statistics] 03/03: Update test tolerances.
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git
commit 0a965fc99b0e90d9e4b29fefc8d2a2d6b2a61f7d
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Sat Dec 11 08:43:29 2021 +0000
Update test tolerances.
The updated gamma function introduced by NUMBERS-174 improves the
accuracy of the Poisson distribution. Values for very large mean for the
CDF and SF agree with the R implementation to 1e-14 relative error. This
improves from the previous gamma function which required 1e-5 relative
error.
---
.../distribution/PoissonDistributionTest.java | 5 +++
.../distribution/test.poisson.3.properties | 6 ++-
.../distribution/test.poisson.5.properties | 50 +++++++++++-----------
.../distribution/test.poisson.6.properties | 42 +++++++++---------
4 files changed, 53 insertions(+), 50 deletions(-)
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
index 103abf4..9936964 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/PoissonDistributionTest.java
@@ -47,6 +47,11 @@ class PoissonDistributionTest extends BaseDiscreteDistributionTest {
return new String[] {"Mean"};
}
+ @Override
+ protected double getRelativeTolerance() {
+ return 1e-14;
+ }
+
//-------------------- Additional test cases -------------------------------
@Test
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.3.properties
index c1b18ef..42f1c4a 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.3.properties
@@ -14,6 +14,8 @@
# limitations under the License.
parameters = 10.0
+tolerance.relative = 5e-14
+tolerance.relative.hp = 5e-14
mean = 10
variance = 10
lower = 0
@@ -55,5 +57,5 @@ logpmf.values = \
-3.83049861817594106128, -4.3611268692381131018 ,\
-4.94891353414022461266, -5.5907674203126234147 ,\
-6.28391460087256348288
-sf.points = 55 60
-sf.values = 7.73802024585487637209e-24, 1.06582832765798891240e-27
+sf.hp.points = 55 60
+sf.hp.values = 7.73802024585487637209e-24, 1.06582832765798891240e-27
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.5.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.5.properties
index 7157cb2..ae0407f 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.5.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.5.properties
@@ -15,13 +15,11 @@
# Large mean (2^31, exceeds the maximum integer value so the distribution is truncated)
parameters = 2147483648
-# TODO: Not very accurate for the CDF and SF.
-# Reference values are from matlab.
-# Reference values have been cross validated using scipy stats and R.
-# CDF/SF values from other implementations are with 1e10 of the matlab results (see below).
+# Reference values are from R.
+# Reference values have been cross validated using scipy stats and matlab.
+# CDF/SF values from other implementations are with 1e10 of the R results (see below).
# scipy stats does not have a high accuracy PMF. The values from R and matlab agree
# and the current SaddlePointExpansion function matches these to 1e-14.
-tolerance.relative = 1e-5
mean = 2147483648
variance = 2147483648
lower = 0
@@ -29,20 +27,33 @@ cdf.points = \
2147311307, 2147340445, 2147375838, 2147407424, 2147424261, 2147444646,\
2147459347, 2147471905, 2147483646, 2147483647
cdf.values = \
- 0.000100001012387873 0.00100002731289315 0.00999708740695301 \
- 0.0500006575457684 0.100006476069800 0.200000459903721 \
- 0.300006293350266 0.399983337909858 0.499988521533539 \
- 0.499997130383385
+ 0.00010000101238876250821 0.00100002731289495529199 \
+ 0.00999708740690409200513 0.05000065754597201456155 \
+ 0.10000647606961658719893 0.20000045990396947415135 \
+ 0.30000629335033379696540 0.39998333790992723901780 \
+ 0.49998852153353817717729 0.49999713038338444714981
pmf.values = \
8.54204406649840e-09, 7.26600783118927e-08, 5.74980516922681e-07,\
2.22559338517785e-06, 3.78727286070677e-06, 6.04134054183580e-06,\
7.50298080972715e-06, 8.33685886179152e-06, 8.60884984227206e-06,\
8.60884984628087e-06
sf.values = \
- 0.999899998987612 0.998999972687107 0.990002912593047 \
- 0.949999342454232 0.899993523930200 0.799999540096279 \
- 0.699993706649734 0.600016662090142 0.500011478466462 \
- 0.500002869616615
+ 0.99989999898761117159 0.99899997268710505338 0.99000291259309591840 \
+ 0.94999934245402795074 0.89999352393038345443 0.79999954009603047034 \
+ 0.69999370664966620303 0.60001666209007264996 0.50001147846646176731 \
+ 0.50000286961661555285
+
+# Matlab
+#cdf.values = \
+# 0.000100001012387873 0.00100002731289315 0.00999708740695301 \
+# 0.0500006575457684 0.100006476069800 0.200000459903721 \
+# 0.300006293350266 0.399983337909858 0.499988521533539 \
+# 0.499997130383385
+#sf.values = \
+# 0.999899998987612 0.998999972687107 0.990002912593047 \
+# 0.949999342454232 0.899993523930200 0.799999540096279 \
+# 0.699993706649734 0.600016662090142 0.500011478466462 \
+# 0.500002869616615
# scipy stats
#cdf.values = \
@@ -57,16 +68,3 @@ sf.values = \
# 0.89999352393038334341, 0.79999954009603047034,\
# 0.69999370664966620303, 0.60001666209007276098,\
# 0.50001147846646187833, nan
-
-# R
-#cdf.values = \
-# 0.00010000101238876250821 0.00100002731289495529199 \
-# 0.00999708740690409200513 0.05000065754597201456155 \
-# 0.10000647606961658719893 0.20000045990396947415135 \
-# 0.30000629335033379696540 0.39998333790992723901780 \
-# 0.49998852153353817717729 0.49999713038338444714981
-#sf.values = \
-# 0.99989999898761117159 0.99899997268710505338 0.99000291259309591840 \
-# 0.94999934245402795074 0.89999352393038345443 0.79999954009603047034 \
-# 0.69999370664966620303 0.60001666209007264996 0.50001147846646176731 \
-# 0.50000286961661555285
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.6.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.6.properties
index 95a0bce..c6d0405 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.6.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.poisson.6.properties
@@ -15,15 +15,13 @@
# Large mean (2^30 * 1.5, exceeds the supported range for the PoissonSampler)
parameters = 1610612736.0
-# TODO: Not very accurate for the CDF and SF.
-# Reference values are from matlab.
-# Reference values have been cross validated using scipy stats and R.
-# CDF/SF values from other implementations are with 1e8 of the matlab results
+# Reference values are from R.
+# Reference values have been cross validated using scipy stats and matlab.
+# CDF/SF values from other implementations are with 1e8 of the R results
# with the exception of the extreme lower/upper x point for scipy which is 1e-6.
# Matlab and R agree more closely at this point.
# scipy stats does not have a high accuracy PMF. The values from R and matlab agree
# and the current SaddlePointExpansion function matches these to 1e-14.
-tolerance.relative = 1e-5
mean = 1610612736
variance = 1610612736
lower = 0
@@ -32,17 +30,21 @@ cdf.points = \
1610572604, 1610612736, 1610652868, \
1610693000, 1610733132, 1610773264
cdf.values = \
- 3.16704406779036e-05 0.00134995175759097 0.0227513157236621 \
- 0.158660921258167 0.500006627095702 0.841345108157004 \
- 0.977248684315580 0.998649864180553 0.999968316218515
+ 3.1670440678036128931e-05 1.3499517575948766484e-03 \
+ 2.2751315723702245086e-02 1.5866092125838993088e-01 \
+ 5.0000662709570131703e-01 8.4134510815686192053e-01 \
+ 9.7724868431562661453e-01 9.9864986418055179396e-01 \
+ 9.9996831621851445249e-01
pmf.values = \
3.33457916373466e-09, 1.10433215078793e-07, 1.34536762949409e-06,\
6.02942126680191e-06, 9.94064355219809e-06, 6.02932110890480e-06,\
1.34538997627176e-06, 1.10449725905628e-07, 3.33601963587828e-09
sf.values = \
- 0.999968329559322 0.998650048242409 0.977248684276338 \
- 0.841339078741833 0.499993372904298 0.158654891842996 \
- 0.0227513156844198 0.00135013581944684 3.16837814853597e-05
+ 9.9996832955932191123e-01 9.9865004824240521941e-01 \
+ 9.7724868427629774104e-01 8.4133907874161006912e-01 \
+ 4.9999337290429873848e-01 1.5865489184313807947e-01 \
+ 2.2751315684373406290e-02 1.3501358194481719987e-03 \
+ 3.1683781485462992721e-05
# scipy stats
#cdf.values = \
@@ -58,16 +60,12 @@ sf.values = \
# 2.27512124794041967e-02, 1.35014109905945011e-03,\
# 3.16836483025270742e-05
-# R
+# matlab
#cdf.values = \
-# 3.1670440678036128931e-05 1.3499517575948766484e-03 \
-# 2.2751315723702245086e-02 1.5866092125838993088e-01 \
-# 5.0000662709570131703e-01 8.4134510815686192053e-01 \
-# 9.7724868431562661453e-01 9.9864986418055179396e-01 \
-# 9.9996831621851445249e-01
+# 3.16704406779036e-05 0.00134995175759097 0.0227513157236621 \
+# 0.158660921258167 0.500006627095702 0.841345108157004 \
+# 0.977248684315580 0.998649864180553 0.999968316218515
#sf.values = \
-# 9.9996832955932191123e-01 9.9865004824240521941e-01 \
-# 9.7724868427629774104e-01 8.4133907874161006912e-01 \
-# 4.9999337290429873848e-01 1.5865489184313807947e-01 \
-# 2.2751315684373406290e-02 1.3501358194481719987e-03 \
-# 3.1683781485462992721e-05
+# 0.999968329559322 0.998650048242409 0.977248684276338 \
+# 0.841339078741833 0.499993372904298 0.158654891842996 \
+# 0.0227513156844198 0.00135013581944684 3.16837814853597e-05