-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathneurons.py
47 lines (41 loc) · 1.32 KB
/
neurons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding=UTF8
#
# python code to plot nonlinearity functions
# written 2015 by Dan Stowell, dedicated to the public domain
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
# plt.rcParams.update({'font.size': 6})
nlfuns = {
'Rectifier (Relu)': ('b', '', lambda x: np.maximum(0, x)),
'Softplus': ('g', '', lambda x: np.log(1 + np.exp( 1 * x))/ 1),
'Sigmoid': ('r', '', lambda x: 1/(1.0+np.exp(-1 * x))),
# 'Exponential': ('c', '', lambda x: np.exp(x))
}
evalpoints = np.linspace(-4, 4, 51)
params = {
'axes.labelsize': 10,
#'text.fontsize': 10,
'legend.fontsize': 10,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'text.usetex': False,
'figure.figsize': [5.5, 4],
'lines.markersize': 4,
}
plt.rcParams.update(params)
plt.figure(frameon=False)
plt.axes(frameon=0)
plt.axvline(0, color=[0.6]*3)
plt.axhline(0, color=[0.6]*3)
for nlname, (color, marker, nlfun) in nlfuns.items():
plt.plot(evalpoints, list(map(nlfun, evalpoints)), hold=True, label=nlname, color=color, marker=marker)
plt.title('Nonlinearities')
plt.xlim(-3, 3)
plt.ylim(-0.1, 2)
plt.legend(loc='upper left', frameon=False)
plt.xlabel('x')
plt.ylabel(u'σ(x)')
plt.savefig('images/Rectifier_and_softplus_functions.svg')
plt.savefig('images/Rectifier_and_softplus_functions.png')
plt.close()