Skip to content

Conversation

phipleg
Copy link
Contributor

@phipleg phipleg commented Apr 21, 2017

Adds the method logsumexp(x, axis, keepdims) to the backend.

Tensorflow (resp. Theano) offers an optimization for computing log(sum(exp(x))) as x_max + log(sum(exp(x - x_max))) that improves numerical stability for large values. It is exposed by tf.reduce_logsumexp (resp. internal graph optimization).

Having this functionality simplifies building a Conditional Random Field with Keras (see PR #4621).



def logsumexp(x, axis=None, keepdims=False):
'''Returns `log(sum(exp(x), axis=axis, keepdims=keepdims))` with improved numerical stability.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one-line docstring summary should fit within 80 chars.

Both added functions need a compliant docstring (# Arguments, # Returns).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It is fixed now.

@fchollet
Copy link
Collaborator

LGTM

@fchollet fchollet merged commit 7d52af6 into keras-team:master Apr 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants