-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplotter.py
94 lines (74 loc) · 2.42 KB
/
plotter.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
__author__ = "Ilya Shoshin (Galarius)"
import numpy as np
from pylab import plt
def sigmoid(s, a=1):
return 1 / (1 + np.exp(-a * s))
def sigmoidPrime(s):
return s * (1 - s)
def sigmoidTanh(s, a=1):
return np.tanh(s / a)
def plotSigmoidPrime(fname=None):
_, ax = plt.subplots()
xs = np.linspace(0.0, 1.0, num=50, endpoint=True)
ys = [sigmoidPrime(x) for x in xs]
ax.plot(xs, ys, "black")
plt.title("y=sigmoid'(s)")
plt.grid(True)
if fname:
plt.savefig(fname)
plt.show()
def plotSigmoidExp(fname=None):
_, ax = plt.subplots()
xs = np.linspace(-10.0, 10.0, num=50, endpoint=True)
ys = [sigmoid(x, 0.9) for x in xs]
ax.plot(xs, ys, "black")
plt.title("y=sigmoid(s)")
plt.grid(True)
if fname:
plt.savefig(fname)
plt.show()
def plotSigmoidTanh(fname=None):
_, ax = plt.subplots()
xs = np.linspace(-10.0, 10.0, num=50, endpoint=True)
ys = [sigmoidTanh(x, 0.9) for x in xs]
ax.plot(xs, ys, "black")
plt.title("y=sigmoid(s)")
plt.grid(True)
if fname:
plt.savefig(fname)
plt.show()
def plotSigmoid(fname=None):
_, ax = plt.subplots()
xs = np.linspace(-10.0, 10.0, num=50, endpoint=True)
ys = [sigmoid(0.5 * x) for x in xs]
ax.plot(xs, ys, "black", linestyle="-", label="sig(0.5 * x)")
ys = [sigmoid(1.0 * x) for x in xs]
ax.plot(xs, ys, "black", linestyle="--", label="sig(1.0 * x)")
ys = [sigmoid(2.5 * x) for x in xs]
ax.plot(xs, ys, "black", linestyle="-.", label="sig(2.5 * x)")
plt.title("y=sig(s * w1)")
plt.grid(True)
if fname:
plt.savefig(fname)
plt.show()
def plotSigmoidBias(fname=None):
_, ax = plt.subplots()
xs = np.linspace(-10.0, 10.0, num=50, endpoint=True)
ys = [sigmoid(1.0 * x - 5.0) for x in xs]
ax.plot(xs, ys, "black", linestyle="-", label="sig(1.0 * x - 1.0 * 5)")
ys = [sigmoid(1.0 * x) for x in xs]
ax.plot(xs, ys, "black", linestyle="--", label="sig(1.0 * x + 1.0 * 0)")
ys = [sigmoid(1.0 * x + 5.0) for x in xs]
ax.plot(xs, ys, "black", linestyle="-.", label="sig(1.0 * x + 1.0 * 5)")
plt.title("y=sig(s * w1 + 1.0 * w2)")
plt.grid(True)
if fname:
plt.savefig(fname)
plt.show()
plotSigmoidPrime("plt_sig_e_prime.png")
plotSigmoidExp("plt_sig_e.png")
plotSigmoidTanh("plt_sig_tanh.png")
plotSigmoid("plt_sig_w1.png")
plotSigmoidBias("plt_sig_w1w2.png")