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

Exponential distribution rate/mean mixup #799

Closed Soren-bundgaard closed 3 years ago

Soren-bundgaard commented 3 years ago

When instantiating an exponential distribution it asks for a rate

val exp = Exponential(1/4)

val cdtAt5 = exp.cdf(5) // gives: 0.9999999979388464, but should be:  0.7134952031398099

I looked at the source code for Exponential and it calls the apache commons math3 ExponentialDistribution, when using pdf and cdf.

That object assumes a mean which would be 4 in the example above. The crude fix is just to call Exponential with the mean, but that results in the mean function returning the rate instead of the mean.

The fix seems to be to change the calls instantiating ExponentialDistribution, such that it uses the mean instead of the rate in the Exponential.scala file

new ExponentialDistribution(rate) -> new ExponentialDistribution(mean)

Im still very new to statistics so please correct me if Im wrong. And Github wouldn't let me make a new branch and a pull request

dlwh commented 3 years ago

thanks for spotting!