Originally posted by **axkr** March 5, 2024
Shouldn't the "convention" be, that if `kernel.density(x)`equals `0.0` the `EmpiricalDistribution#density()` method should also return `0.0` and not `NaN` if `kB(binIndex)==0.0` ?
https://github.com/Hipparchus-Math/hipparchus/blob/a8fe2cf6f868329820544f74c784aa9de34dc695/hipparchus-stat/src/main/java/org/hipparchus/stat/fitting/EmpiricalDistribution.java#L581
So the patch could be something like this?
```java
public double density(double x) {
if (x < min || x > max) {
return 0d;
}
final int binIndex = findBin(x);
final RealDistribution kernel = getKernel(binStats.get(binIndex));
double kernelDensity = kernel.density(x);
if (kernelDensity == 0d) {
return 0d;
}
return kernelDensity * pB(binIndex) / kB(binIndex);
}
```
Discussed in https://github.com/Hipparchus-Math/hipparchus/discussions/315