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
The following commit(s) were added to refs/heads/master by this push: new 19d6f8a Added additional log density tests for Nakagami distribution 19d6f8a is described below commit 19d6f8a97d6d8e06e3de158d6a3a2f0e1c77c25c Author: aherbert <aherb...@apache.org> AuthorDate: Thu Nov 24 17:56:03 2022 +0000 Added additional log density tests for Nakagami distribution --- .../distribution/NakagamiDistributionTest.java | 56 ++++++++++++++++++---- .../distribution/test.nakagami.1.properties | 6 +-- .../distribution/test.nakagami.2.properties | 6 +-- .../distribution/test.nakagami.3.properties | 6 +-- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java index 7cb1978..41f1101 100644 --- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java +++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java @@ -16,10 +16,11 @@ */ package org.apache.commons.statistics.distribution; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; /** * Test cases for {@link NakagamiDistribution}. @@ -124,12 +125,49 @@ class NakagamiDistributionTest extends BaseContinuousDistributionTest { testMoments(dist, mean, variance, tolerance); } - @Test - void testExtremeLogDensity() { - // XXX: Verify with more test data from a reference distribution - final NakagamiDistribution dist = NakagamiDistribution.of(0.5, 1); - final double x = 50; - Assertions.assertEquals(0.0, dist.density(x)); - Assertions.assertEquals(-1250.22579, dist.logDensity(x), 1e-4); + /** + * Test log density where the density is zero. + */ + @ParameterizedTest + @MethodSource + void testAdditionalLogDensity(double mu, double omega, double[] x, double[] expected) { + final NakagamiDistribution dist = NakagamiDistribution.of(mu, omega); + testLogDensity(dist, x, expected, DoubleTolerances.relative(1e-15)); + } + + static Stream<Arguments> testAdditionalLogDensity() { + final double[] x = {50, 55, 60, 80, 120}; + return Stream.of( + // scipy.stats 1.9.3 (no support for omega): + // nakagami.logpdf(x, 0.5) + Arguments.of(0.5, 1, x, + new double[]{-1250.2257913526448, -1512.7257913526448, -1800.2257913526448, + -3200.2257913526446, -7200.225791352645}), + // nakagami.logpdf(x, 1.5) (no support for omega) + Arguments.of(1.5, 1, x, + new double[]{-3740.7538269087863, -4528.063206549177, -5390.389183795199, + -9589.813819650295, -21589.00288943408}), + // R nakagami 1.1.0 package: + // print(dnaka(x, 0.5, 2, log=TRUE), digits=17) + Arguments.of(0.5, 2, x, + new double[]{-625.57236494292476, -756.82236494292465, -900.57236494292465, + -1600.57236494292442, -3600.57236494292420}), + // print(dnaka(x, 0.5, 0.75, log=TRUE), digits=17) + Arguments.of(0.5, 0.75, x, + new double[]{-1666.7486169830854, -2016.7486169830854, -2400.0819503164184, + -4266.7486169830854, -9600.0819503164203}), + // print(dnaka(x, 1.5, 0.75, log=TRUE), digits=17) + Arguments.of(1.5, 0.75, x, + new double[]{-4990.3223038001088, -6040.1316834404988, -7189.9576606865212, + -12789.3822965416184, -28788.5713663254028}), + // print(dnaka(x, 1.5, 1.75, log=TRUE), digits=17) + Arguments.of(1.5, 1.75, x, + new double[]{-2134.4503934478316, -2584.2597730882230, -3076.9428931913867, + -5476.3675290464835, -12332.6994559731247}), + // print(dnaka(x, 1.5, 7.75, log=TRUE), digits=17) + Arguments.of(1.5, 7.75, x, + new double[]{-477.69633391576963, -579.11861678196749, -690.23491660863317, + -1231.59503633469740, -2779.17120289267450}) + ); } } diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties index d86c34c..16d2178 100644 --- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties +++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties @@ -28,9 +28,9 @@ cdf.values = \ 6.82689492137085852e-01, 7.69860659556583560e-01,\ 8.38486681532458089e-01, 8.90401416600884343e-01,\ 9.28139361774148575e-01, 9.54499736103641472e-01 -# pdf adjusted to return 0 for x=0. -# scioy and matlab compute a value. -# WolframAlpha returns zero. +# pdf adjusted to return 0 for x=0 (value is undefined at x=0). +# scipy and matlab compute a value. +# WolframAlpha returns zero. R nakagami NaN. pdf.values = \ 0.0, 0.79788416186068489, 0.78208538795091187,\ 0.73654028060664678, 0.66644920578359934, 0.57938310552296557,\ diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties index bcb8dd9..9718e7b 100644 --- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties +++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties @@ -25,9 +25,9 @@ cdf.values = \ 0.0899803073877229 0.189070530913232 0.317729669663787 \ 0.460129965238200 0.599031192110653 0.720732382881390 \ 0.817659600745483 0.888389774905288 -# pdf adjusted to return 0 for x=0. -# scioy and matlab compute a value. -# WolframAlpha returns zero. +# pdf adjusted to return 0 for x=0 (value is undefined at x=0). +# scipy and matlab compute a value. +# WolframAlpha returns zero. R nakagami NaN. pdf.values = \ 0 1.46580643635352e-06 0.0568994550428125 0.208008745554258 \ 0.402828269545621 0.580491109555755 0.692398452624549 \ diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties index 3506fbc..ba9d8ab 100644 --- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties +++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties @@ -26,9 +26,9 @@ cdf.values = \ 0.41599060641445568, 0.53633771818837206, 0.63551561797542433,\ 0.71746556659624028, 0.7845448997061909, 0.83861986211366601,\ 0.88141004735798412, 0.91458032800205946, 0.93973541101651015 -# pdf adjusted to return 0 for x=0. -# scioy and matlab compute a value. -# WolframAlpha returns zero. +# pdf adjusted to return 0 for x=0 (value is undefined at x=0). +# scipy and matlab compute a value. +# WolframAlpha returns zero. R nakagami NaN. pdf.values = \ 0.0, 5.17638635039373352, 0.8734262427029803,\ 0.66605658341650675, 0.54432849968092045, 0.45048535438453824,\