From 8e63d421bff30f6ab69d731f93b9ca8fc3fb95ba Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Mon, 2 Aug 2021 01:17:48 +0200 Subject: [PATCH] Adapt to "Commons Statistics" API change. --- .../legacy/distribution/AbstractRealDistribution.java | 11 ----------- .../legacy/distribution/EmpiricalDistribution.java | 9 --------- .../distribution/EnumeratedRealDistribution.java | 10 +--------- .../distribution/AbstractRealDistributionTest.java | 10 ---------- .../distribution/EnumeratedRealDistributionTest.java | 4 ++-- 5 files changed, 3 insertions(+), 41 deletions(-) diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java index afedfae1e..e422e17c3 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistribution.java @@ -202,17 +202,6 @@ public abstract class AbstractRealDistribution return SOLVER_DEFAULT_ABSOLUTE_ACCURACY; } - /** - * {@inheritDoc} - * - * @return zero. - * @since 3.1 - */ - @Override - public double probability(double x) { - return 0d; - } - /** * {@inheritDoc} *

diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java index 3fd8bbf4c..9e473e807 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EmpiricalDistribution.java @@ -303,15 +303,6 @@ public final class EmpiricalDistribution extends AbstractRealDistribution // Distribution methods. - /** - * {@inheritDoc} - * @since 3.1 - */ - @Override - public double probability(double x) { - return 0; - } - /** * {@inheritDoc} * diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistribution.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistribution.java index f90789477..bae7540e0 100644 --- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistribution.java +++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistribution.java @@ -122,14 +122,6 @@ public class EnumeratedRealDistribution } - /** - * {@inheritDoc} - */ - @Override - public double probability(final double x) { - return innerDistribution.probability(x); - } - /** * For a random variable {@code X} whose values are distributed according to * this distribution, this method returns {@code P(X = x)}. In other words, @@ -141,7 +133,7 @@ public class EnumeratedRealDistribution */ @Override public double density(final double x) { - return probability(x); + return innerDistribution.probability(x); } /** diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistributionTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistributionTest.java index a836f14e4..c75003783 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistributionTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/AbstractRealDistributionTest.java @@ -96,11 +96,6 @@ public class AbstractRealDistributionTest { public boolean isSupportConnected() { return false; } - - @Override - public double probability(final double x) { - throw new UnsupportedOperationException(); - } }; final double expected = x1; final double actual = distribution.inverseCumulativeProbability(p12); @@ -196,11 +191,6 @@ public class AbstractRealDistributionTest { public boolean isSupportConnected() { return false; } - - @Override - public double probability(final double x) { - throw new UnsupportedOperationException(); - } }; final double expected = x2; final double actual = distribution.inverseCumulativeProbability(p23); diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistributionTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistributionTest.java index 96414d16e..e7fc63c67 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistributionTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/distribution/EnumeratedRealDistributionTest.java @@ -99,7 +99,7 @@ public class EnumeratedRealDistributionTest { double[] points = new double[]{-2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}; double[] results = new double[]{0, 0.2, 0, 0, 0, 0.5, 0, 0, 0, 0.3, 0}; for (int p = 0; p < points.length; p++) { - double density = testDistribution.probability(points[p]); + double density = testDistribution.density(points[p]); Assert.assertEquals(results[p], density, 0.0); } } @@ -248,7 +248,7 @@ public class EnumeratedRealDistributionTest { public void testCreateFromDoubles() { final double[] data = new double[] {0, 1, 1, 2, 2, 2}; EnumeratedRealDistribution distribution = new EnumeratedRealDistribution(data); - assertEquals(0.5, distribution.probability(2), 0); + assertEquals(0.5, distribution.density(2), 0); assertEquals(0.5, distribution.cumulativeProbability(1), 0); } }