Discussion:
[math] Proposal: logsumexp
Ahmed Fasih
2018-11-16 20:56:45 UTC
Permalink
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-***@commons.apache.org
For additional commands, e-mail: dev-***@commons.apache.org
Gilles
2018-11-17 00:37:27 UTC
Permalink
Hello.


Thank you for your interest in the "Commons Math" library.
However, you should be aware that some of its functionality is in the
process of being transferred to more focused components:
* Commons Numbers
* Commons RNG
* Commons Statistics
* Commons Geometry

In particular, a method such as you describe could perhaps have its
place in the "commons-numbers-arrays" module of "Numbers".[1]

Regards,
Gilles

[1]
https://git1-us-west.apache.org/repos/asf?p=commons-numbers.git;a=tree;f=commons-numbers-arrays/src/main/java/org/apache/commons/numbers/arrays
Post by Ahmed Fasih
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
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
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-***@commons.apache.org
For additional commands, e-mail: dev-***@commons.apache.org
Ahmed Fasih
2018-11-21 14:54:58 UTC
Permalink
Gilles, thanks for writing!, and sorry for the delay in responding.
Post by Gilles
However, you should be aware that some of its functionality is in the
* Commons Numbers
* Commons RNG
* Commons Statistics
* Commons Geometry
In particular, a method such as you describe could perhaps have its
place in the "commons-numbers-arrays" module of "Numbers".[1]
Thank you, this is very interesting! What is the plan for Commons Math—will it go away and all its functionality be split between these packages? Or will it coexist with these other packages? How will the overlap in functionality be handled?

I saw that the Commons Numbers package hasn't yet had a formal release. Do you know if the team has a timeline on releasing it?

I ask all these questions because I'm wondering what my next steps should be towards getting `logsumexp` into either Commons Math or Commons Numbers or both.

Any insight you have will be appreciated! Thanks,

Ahmed

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@commons.apache.org
For additional commands, e-mail: dev-***@commons.apache.org
Gilles
2018-11-21 15:36:55 UTC
Permalink
Hello.
Post by Ahmed Fasih
Gilles, thanks for writing!, and sorry for the delay in responding.
Post by Gilles
However, you should be aware that some of its functionality is in the
* Commons Numbers
* Commons RNG
* Commons Statistics
* Commons Geometry
In particular, a method such as you describe could perhaps have its
place in the "commons-numbers-arrays" module of "Numbers".[1]
Thank you, this is very interesting! What is the plan for Commons
Math—will it go away and all its functionality be split between these
packages?
It will depend on how much work contributors are willing to
put into the refactoring. [Help is certainly needed even for
finalizing an initial round that actually started more than
3 years ago...]
Post by Ahmed Fasih
Or will it coexist with these other packages? How will the
overlap in functionality be handled?
Ideally, there is no overlap: Whatever exists in the new
components has been deleted (or will be) from Commons Math.
What will remain in the next release of Commons Math is either
* truly high-level functionality (e.g. package "ode") or
* some large chunks of code that require a lot of work to be
worth moving into its own component (e.g. package "linear") or
* widely useful functionality that lack a "porting team" (e.g.
package "stat")

[Mostly these categories overlap, making CM a nightmare to
maintain. Hence the only way forward being new components
with more focused scopes.]
Post by Ahmed Fasih
I saw that the Commons Numbers package hasn't yet had a formal
release. Do you know if the team has a timeline on releasing it?
Realistically, no.
A lot of work has already gone into it, but we lack contributors
to review and fix the new found issues.
I was contemplating making a release of a selected set of components
but even so, review is needed to make the choice on a sound basis.
Post by Ahmed Fasih
I ask all these questions because I'm wondering what my next steps
Want to join the "team"? :-)
Post by Ahmed Fasih
should be towards getting `logsumexp`
into either Commons Math
Since the last release, only bug fixes go into Commons Math.
Post by Ahmed Fasih
or
Commons Numbers
Would be a good fit for the "commons-numbers-arrays" module.
What remains to be seen is whether some minimal "framework"
can be designed in order to make such functionality easy to
use with newer JDKs (functional interface, streams, ...).
Post by Ahmed Fasih
or both.
:-/

Regards,
Gilles
Post by Ahmed Fasih
Any insight you have will be appreciated! Thanks,
Ahmed
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-***@commons.apache.org
For additional commands, e-mail: dev-***@commons.apache.org

Loading...