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

Add modified_tanh activation function #1411

Merged
merged 4 commits into from
Sep 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions n3fit/src/n3fit/backends/keras_backend/base_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
The names of the layer and the activation function are the ones to be used in the n3fit runcard.
"""

from tensorflow.keras.layers import Dense, Lambda, LSTM, Dropout, Concatenate, concatenate, Input
from tensorflow.keras.layers import Lambda, LSTM, Dropout, Concatenate
from tensorflow.keras.layers import concatenate, Input # pylint: disable=unused-import
from tensorflow.keras.layers import Dense as KerasDense
from tensorflow import expand_dims
from tensorflow.keras.regularizers import l1_l2
from tensorflow import nn
from tensorflow import nn, math

from n3fit.backends import MetaLayer

Expand All @@ -30,14 +31,19 @@ def square_activation(x):
""" Squares the input """
return x*x

def modified_tanh(x):
""" A non-saturating version of the tanh function """
return math.abs(x)*nn.tanh(x)

def leaky_relu(x):
""" Computes the Leaky ReLU activation function """
return nn.leaky_relu(x, alpha=0.2)

custom_activations = {
"square" : square_activation,
"leaky_relu": leaky_relu,
}
"square" : square_activation,
"leaky_relu": leaky_relu,
"modified_tanh": modified_tanh,
}

def LSTM_modified(**kwargs):
"""
Expand Down