In [16]:
import keras
from os import sys, path
sys.path.append(path.abspath('../src'))
from utils import plot_activations, plot_activations_distributions
%pylab inline
def sigmoid(x):
return 1 / (1 + np.exp(-x))
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(sigmoid)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(sigmoid)
In [17]:
def tanh(x):
return np.tanh(x)
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(tanh, show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(tanh)
In [18]:
pylab.rcParams['figure.figsize'] = (7,3)
def relu(x):
return np.maximum(0, x)
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(relu, show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(relu)
In [19]:
def selu(x):
alpha = 1.6732632423543772848170429916717
scale = 1.0507009873554804934193349852946
if x > 0:
return scale * x
return scale * (alpha * (np.exp(x) - 1))
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(selu, show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(selu)
In [20]:
def SeNLU(x):
alpha = 1.758099340847376859940217520812
sigx = np.sign(x)
return - sigx * alpha * (np.exp(- sigx * x) - 1)
# Or ...
if x > 0:
return - alpha * (np.exp(- x) - 1)
return alpha * (np.exp(x) - 1)
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(SeNLU, show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(SeNLU)
In [26]:
def SeNLU2(x):
alpha = 1.758099340847376859940217520812
x = x - alpha # shift is important !
sign = -1 if x < 0 else 1
return - sign * alpha * (np.exp(sign * (-x)) - 1) + alpha
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(SeNLU2, show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(SeNLU2, n_mean=1.758, xlim=[-0.242, 3.758])
In [ ]:
def perso(x):
if np.abs(x) > 2:
return np.sign(x)
if np.abs(x) > 0.2:
return (1 / 3. * x) + np.sign(x) * 1 / 3.
return 2 * x
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(perso, range=[-3,3,0.01], show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(perso, xlim=[-2, 2])
In [ ]:
def perso2(x):
if np.abs(x) > 1.59:
return - 2 * np.sign(x) * (np.exp(np.sign(- x) * x) - 1)
return x
pylab.rcParams['figure.figsize'] = (7,3)
plot_activations(perso2, range=[-3,3,0.01], show_id=True)
print '---'
pylab.rcParams['figure.figsize'] = (15, 4)
plot_activations_distributions(perso2, xlim=[-2, 2])