1. sin, cos
import math
import matplotlib.pyplot as plt
low, high = 0, 4 * PI
n_data = 1000
interval = (high-low) / (n_data-1)
linspace = [low + interval * idx for idx in range(n_data)]
# method.1
sin = list()
cos = list()
for data in linspace:
sin.append(math.sin(data))
cos.append(math.cos(data))
# method.2
sin = [ math.sin(data) for data in linspace ]
cos = [ math.cos(data) for data in linspace ]
fig, ax = plt.subplots(figsize=(10,5))
ax.plot(linspace, sin, label='sin')
ax.plot(linspace, cos, label='cos')
ax.legend(fontsize=10)

2. exp, log
import math
import matplotlib.pyplot as plt
low, high = 0.01, 10
n_data = 10000
interval = (high-low) / (n_data-1)
linspcae = [low + interval * idx for idx in range(n_data)]
exp = [math.exp(data) for data in linspace]
log = [math.log(data) for data in linspace]
fig, axes = plt.subplots(2, 1, figsize=(10,5))
axes[0].plot(linspace, exp, label='exp')
axes[1].plot(linspace, log, label='log')
axes[0].legend(fontsize=10)
axes[1].legend(fontsize=10)
for ax_idx, ax in enumerate(axes.flat):
ax.axvline(x=0, color='k', linestyle=':')
ax.axhline(y=0, color='k', linestyle=':')
ax.tick_params(labelsize=20)

3. sigmoid, tanh ReLU
3.1 Sigmoid
import math
import matplotlib.pyplot as plt
low, high = -10, 10
n_data = 100
interval = (high-low) / (n_data-1)
linspace = [low + interval * idx for idx in range(n_data)]
sigmoid = [1 / (1 + math.exp(-x)) for x in linspace]
fig, ax = plt.subplots(figsize=(15,5))
ax.plot(linspace, sigmoid, label='Sigmoid')
ax.legend(fontsize = 10)
ax.grid()

3.2 Tanh
import math
import matplotlib.pyplot as plt
low, high = -10, 10
n_data = 100
interval = (high-low) / (n_data-1)
linspace = [low + interval*idx for idx in range(n_data)]
# method.1
tanh = list()
for x in linspace:
sinh = math.exp(x) - math.exp(-x)
cosh = math.exp(x) + math.exp(-x)
tanh.append(sinh/cosh)
# method.2
tanh = [(math.exp(x)-math.exp(-x)) / (math.exp(x)+math.exp(-x)) for x in linspace]
fig, ax = plt.subplots(figsize=(15,5))
ax.plot(linspace, tanh, label='tanh')
ax.legend(fontsize=10)
ax.grid()

3.3 ReLU
import math
import matplotlib.pyplot as plt
low, high = -10, 10
n_data = 100
interval = (high-low) / (n_data-1)
linspace = [low + interval*idx for idx in range(n_data)]
relu = [max(0,x) for x in linspace]
fig, ax = plt.subplots(figsize=(15,5))
ax.plot(linspace, relu, label='ReLU')
ax.legend(fontsize=10)
ax.grid()

import math
import matplotlib.pyplot as plt
low, high = 0.001, 0.999
n_data = 100
interval = (high-low) / (n_data-1)
linspace = [low + interval * idx for idx in range(n_data)]
info = [-math.log(p) for p in linspace]
fig, ax = plt.subplots(figsize=(15,5))
ax.plot(linspace, info, label='information Graph')
ax.legend(fontsize=10)
ax.set_xlabel("Probability", fontsize=20)
ax.set_ylabel("Information", fontsize=20)
ax.tick_params(labelsize=15)
ax.grid()

4.2 Binary Entropy
import math
import matplotlib.pyplot as plt
low, high = 0.001, 0.999
n_data = 100
interval = (high-low) / (n_data-1)
linspace = [low + interval*idx for idx in range(n_data)]
binary_entropy = [-(p*math.log(p) + (1-p)*math.log(1-p)) for p in linspace]
fig, ax = plt.subplots(figsize=(15,5))
ax.plot(linspace, binary_entropy, label='Binary Entropy')
ax.legend(fontsize=10)
ax.set_xlabel("Probability", fontsize=20)
ax.set_ylabel("Binary Entropy", fontsize=20)
ax.tick_params(labelsize=15)
ax.grid()
