osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[math] Proposal: logsumexp


Hello friends, I'm new to Java, and to Apache Commons Math, and I'm porting some code to Java. One useful function that's available in Scipy is `logsumexp`:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html

In a nutshell, given a list of values in the log domain, the function numerically-stably sums them, yielding the result still in the log domain.

This is useful for me because I need to add and subtract the results of the log-Gamma function (via your `Gamma.logGamma`). For *subtraction,* Scipy's `logsumexp` can accept a *second* list giving the scalars to apply to each value (e.g., +1, -1), and returns both the magnitude *and* sign of the result.

I would like feedback on adding `logsumexp` to Apache Commons Math. I have ported the Python version, from

https://github.com/scipy/scipy/blob/5e5a2d2a47b9011be2f73971bba94b3e158936c5/scipy/special/_logsumexp.py#L9-L130

to Java, which lives at:

https://github.com/fasiha/ebisu-java/blob/2b651071b37aac5f85e8cb4c07ea7a1e14bb175c/src/main/java/me/aldebrn/ebisu/Ebisu.java#L33-L69

As mentioned above, I'm a beginner, and am experimenting with Java 8 Collections, etc., so I am embarrassed by my mixing of `List` and plain arrays in this last link above. Assuming that you think it would be a good addition to Math, I'm totally open to suggestions to improve the API.

Many thanks,

Ahmed

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxxxxxx