scalala / Scalala

Scalala has been superseded by dlwh/breeze. Scalala is a high performance numeric linear algebra library for Scala, with rich Matlab-like operators on vectors and matrices; a library of numerical routines; support for plotting.
http://groups.google.com/group/scalala
GNU Lesser General Public License v2.1
298 stars 30 forks source link

scalala.library.numerics.erf() is incorrect about 0.0 #36

Closed duckworthd closed 12 years ago

duckworthd commented 12 years ago

For example,

scala> Numerics.erf(-0.5) res39: Double = -0.5206970701578215

scala> Numerics.erf(0.0) res40: Double = 1.0

scala> Numerics.erf(0.5) res41: Double = 0.5206970701578215

Numerics.erf(0.0) should = 0.0

dramage commented 12 years ago

Yikes, you're right we're off by quite a bit here. I think the broader question is if we ought to be wrapping some other library where other people have worked out the numerical stability of the function approximations or if we should be redoing that work here. This is originally dlwh's code. Any opinion, David?

duckworthd commented 12 years ago

For this issue I used another approximation off of wikipedia for erf() and erfi() based on the cited paper.

https://gist.github.com/1520395

More generally though, it seems that the most popular scientific library for Java is Michael Flanagan's. Personally, I don't see any reason not to fall back on a well-tested library for common functions -- the only question is who's willing to implement the necessary changes.

dlwh commented 12 years ago

Flanagan's code is a no-go, since it's incompatible with GPL.

I'll patch the code for now and we'll discuss adding another dependency. Commons or Colt seem like the best options.