From 57f8f3fe6b2dcca076510ec225bd22da617814f2 Mon Sep 17 00:00:00 2001 From: axexlck Date: Wed, 6 Mar 2024 18:31:20 +0100 Subject: [PATCH] Fix #316 EmpiricalDistribution#density() shouldn't return NaN see discussion in #315 --- .../org/hipparchus/stat/fitting/EmpiricalDistribution.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java b/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java index 20c77480b..137936f7d 100644 --- a/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java +++ b/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java @@ -578,7 +578,11 @@ public double density(double x) { } final int binIndex = findBin(x); final RealDistribution kernel = getKernel(binStats.get(binIndex)); - return kernel.density(x) * pB(binIndex) / kB(binIndex); + double kernelDensity = kernel.density(x); + if (kernelDensity == 0d) { + return 0d; + } + return kernelDensity * pB(binIndex) / kB(binIndex); } /**