Skip to content

Commit

Permalink
Add softsign in numpy backend (keras-team#11879)
Browse files Browse the repository at this point in the history
  • Loading branch information
kouml authored and Frédéric Branchaud-Charron committed Dec 17, 2018
1 parent ca802e1 commit bf0f25f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keras/backend/numpy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def softplus(x):
return np.log(1. + np.exp(x))


def softsign(x):
return x / (1 + np.abs(x))


def elu(x, alpha=1.):
return x * (x > 0) + alpha * (np.exp(x) - 1.) * (x < 0)

Expand Down
2 changes: 2 additions & 0 deletions keras/backend/tensorflow_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,8 @@ def softsign(x):
# Returns
A tensor.
{{np_implementation}}
"""
return tf.nn.softsign(x)

Expand Down
1 change: 1 addition & 0 deletions tests/keras/backend/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ def test_relu(self, alpha, max_value, threshold):
max_value=max_value, threshold=threshold)

def test_nn_operations(self):
check_single_tensor_operation('softsign', (4, 10), WITH_NP)
check_single_tensor_operation('softplus', (4, 10), WITH_NP)
check_single_tensor_operation('elu', (4, 10), WITH_NP, alpha=0.5)

Expand Down

0 comments on commit bf0f25f

Please sign in to comment.