Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95F72109B8 for ; Sun, 8 Mar 2015 22:11:12 +0000 (UTC) Received: (qmail 82970 invoked by uid 500); 8 Mar 2015 22:11:12 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 82889 invoked by uid 500); 8 Mar 2015 22:11:12 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 82880 invoked by uid 99); 8 Mar 2015 22:11:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Mar 2015 22:11:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2CEE2DFD4C; Sun, 8 Mar 2015 22:11:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: psteitz@apache.org To: commits@commons.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [math] Made getKernel return a constant distribution for zero variance bins. JIRA: MATH-1203. Date: Sun, 8 Mar 2015 22:11:12 +0000 (UTC) Repository: commons-math Updated Branches: refs/heads/MATH_3_X 9aa638267 -> 59912a072 Made getKernel return a constant distribution for zero variance bins. JIRA: MATH-1203. Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/59912a07 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/59912a07 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/59912a07 Branch: refs/heads/MATH_3_X Commit: 59912a0724200beef63df2d74497165c3d1081bf Parents: 9aa6382 Author: Phil Steitz Authored: Sun Mar 8 15:11:03 2015 -0700 Committer: Phil Steitz Committed: Sun Mar 8 15:11:03 2015 -0700 ---------------------------------------------------------------------- src/changes/changes.xml | 3 +++ .../commons/math3/random/EmpiricalDistribution.java | 2 +- .../math3/random/EmpiricalDistributionTest.java | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/59912a07/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b512dc8..03d6fa9 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces! + + EmpiricalDistribution getKernel fails for buckets with only multiple instances of the same value. + "UnivariateSolverUtils#bracket(...)" sometimes failed to bracket if a reached the lower bound. http://git-wip-us.apache.org/repos/asf/commons-math/blob/59912a07/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java b/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java index 3dd2d7f..fc27300 100644 --- a/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java +++ b/src/main/java/org/apache/commons/math3/random/EmpiricalDistribution.java @@ -826,7 +826,7 @@ public class EmpiricalDistribution extends AbstractRealDistribution { * @return within-bin kernel parameterized by bStats */ protected RealDistribution getKernel(SummaryStatistics bStats) { - if (bStats.getN() == 1) { + if (bStats.getN() == 1 || bStats.getVariance() == 0) { return new ConstantRealDistribution(bStats.getMean()); } else { return new NormalDistribution(randomData.getRandomGenerator(), http://git-wip-us.apache.org/repos/asf/commons-math/blob/59912a07/src/test/java/org/apache/commons/math3/random/EmpiricalDistributionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/math3/random/EmpiricalDistributionTest.java b/src/test/java/org/apache/commons/math3/random/EmpiricalDistributionTest.java index 42e9a7f..580be9e 100644 --- a/src/test/java/org/apache/commons/math3/random/EmpiricalDistributionTest.java +++ b/src/test/java/org/apache/commons/math3/random/EmpiricalDistributionTest.java @@ -433,6 +433,21 @@ public final class EmpiricalDistributionTest extends RealDistributionAbstractTes } /** + * MATH-1203 + */ + @Test + public void testNoBinVariance() { + final double[] data = {0, 0, 1, 1}; + EmpiricalDistribution dist = new EmpiricalDistribution(2); + dist.load(data); + dist.reseedRandomGenerator(1000); + for (int i = 0; i < 1000; i++) { + final double dev = dist.sample(); + Assert.assertTrue(dev == 0 || dev == 1); + } + } + + /** * Find the bin that x belongs (relative to {@link #makeDistribution()}). */ private int findBin(double x) {