Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logsumexp to backend. #6346

Merged
merged 1 commit into from
Apr 22, 2017
Merged

Added logsumexp to backend. #6346

merged 1 commit into from
Apr 22, 2017

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).

@@ -1274,6 +1274,13 @@ def log(x):
return tf.log(x)


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