scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 693 forks source link

postive density for Gamma.pdf called on negative numbers #762

Closed cgled closed 4 years ago

cgled commented 4 years ago

If I'm not mistaken, the gamma distribution has positive support, so the density function should not be negative when called on negative numbers.

However:

g: breeze.stats.distributions.Gamma = Gamma(1.0,0.1)

scala> g.pdf(-.1)
res0: Double = 9.999999999999998

on the other hand, the cdf is as I'd expect:

scala> g.cdf(-.10)
res3: Double = 0.0

Looking at the source, there are some special cases for the density function returning a positive value when the argument is negative; I'm not sure what the rationale is for these.

dlwh commented 4 years ago

(Sorry for the slow response. it appears I stopped receiving github notifications.)

Good catch. I don't know why it's like this. I'll fix soon